small medium large xlarge

03 May 2008, 19:11
Alan Bonde (1 post)

I haven’t been able to get the proper results with the IRB using the “meeting_path” or “meeting_url” methods. I get the following results.

C:\ruby\work\user_group>ruby script/console
Loading development environment (Rails 2.0.2)
>> meeting = Meeting.find(1)
=> #<Meeting id: 1, meets_on: "2007-12-06", location: "University Library", desc
ription: "Rails Hackfest", created_at: "2008-04-30 16:29:33", updated_at: "2008-
04-30 16:32:22">
>> meeting_path(:id =>
NoMethodError: undefined method `meeting_path' for #<Object:0x27bf9ec>
        from (irb):2

I get the correct results when I implement them in the index.html.erb file as shown on page 126.

Any ideas?

Win XP, Rails 2.0.2, Ruby 1.8.6

14 May 2008, 19:22
Derek DeVries (18 posts)

The named routes helper methods aren’t available within top level scope in the console. They are available within the view files (index.html.erb) because Rails automatically includes them as helpers within our controllers and views. To use these methods in the console you need to first include the ActionController::UrlWriter module.

user_group> ruby script/console 
Loading development environment (Rails 2.0.2)
>> include ActionController::UrlWriter
=> Object
>> meeting_path(:id => 1)
=> "/meetings/show/1"