Testing routes in the console

前端 未结 3 1507
-上瘾入骨i
-上瘾入骨i 2021-01-31 03:10

What do I have to do so that this will work in the console (assuming song is defined, obviously):

edit_song(:id => song.id)
相关标签:
3条回答
  • 2021-01-31 03:32

    You have access to an app object which you can use to test routes on.

    >> app.root_url
    => "http://www.example.com/"
    >> app.root_path
    => "/"
    
    0 讨论(0)
  • 2021-01-31 03:41
    > script/console
    song = Song.first
    edit_song_path(:id=>song.id)
    

    assumes (routes.rb)

       map.resources :songs
    
    0 讨论(0)
  • 2021-01-31 03:51

    The following imports named helpers for me in 3.2.8:

    > include Rails.application.routes.url_helpers
    
    0 讨论(0)
提交回复
热议问题