Tom Lehman
Tom Lehman

Reputation: 89373

Testing routes in the console

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

edit_song(:id => song.id)

Upvotes: 35

Views: 14433

Answers (3)

Xavier Shay
Xavier Shay

Reputation: 4127

The following imports named helpers for me in 3.2.8:

> include Rails.application.routes.url_helpers

Upvotes: 16

ndp
ndp

Reputation: 22016

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

assumes (routes.rb)

   map.resources :songs

Upvotes: 1

theIV
theIV

Reputation: 25794

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
=> "/"

Upvotes: 75

Related Questions