2009-09-09 73 views
32

什麼我必須這樣做,這將在控制檯中工作(假設song定義,很明顯):測試路線在控制檯

edit_song(:id => song.id) 
+0

你可以用'耙routes'看它們的列表,儘管它不能將對象扔進它們。 – Garrett 2009-09-09 05:15:20

回答

68

你有機會獲得一個app對象,你可以用它來測試路線。

>> app.root_url 
=> "http://www.example.com/" 
>> app.root_path 
=> "/" 
+1

很高興知道控制檯中有'應用程序'!謝謝 ! – 2009-09-09 13:56:01

+0

這在Rails 3中不起作用。 – 2012-07-05 08:00:11

+0

@MichieldeMare真的嗎?它在Rails 3.0.7中適用於我。它不再適用於Rails 3.2嗎? – theIV 2012-07-05 14:15:35

1
> script/console 
song = Song.first 
edit_song_path(:id=>song.id) 

假設(的routes.rb)

map.resources :songs 
12

命名爲我的助手以下進口3.2.8:

> include Rails.application.routes.url_helpers