Simply Rails2: Ch 9, pg 334 undefined method `user_path'

Hi,

For some reason, my “<span><%= link_to @story.user.login, @story.user %></span>” update to the view/stories/show.html.erb isn’t working. It’s not building the URL for @story.user

Any help is appreciated. --Thanks

I did check and the following works:
<span><%= link_to @story.user.login, { :controller => ‘users’, :action => ‘show’, :id => @story.user.to_param } %></span>

Producing URL Location: /users?id=1-perry

Console shows the methods working:

>> s.user.login
=> “perry”
>> s.user.to_param
=> “1-perry”

Error Message:::
NoMethodError in Stories#show

Showing app/views/stories/show.html.erb where line #20 raised:

undefined method `user_path’ for #ActionView::Base:0x4e33a60

Extracted source (around line #20):

17:


18:


19: Submitted by:
20: <%= link_to @story.user.login, @story.user %>
21:


22:


23: <%= link_to @story.link, @story.link %>

RAILS_ROOT: C:/www/rails/SimplyRails2/shovell
Application Trace | Framework Trace | Full Trace

c:/addons/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/polymorphic_routes.rb:109:in __send__' c:/addons/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/polymorphic_routes.rb:109:in polymorphic_url’
c:/addons/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/polymorphic_routes.rb:116:in polymorphic_path' c:/addons/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/url_helper.rb:91:in url_for’
c:/addons/ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_view/helpers/url_helper.rb:228:in link_to' C:/www/rails/SimplyRails2/shovell/app/views/stories/show.html.erb:20:in _run_erb_app47views47stories47show46html46erb’

You may want to check your config/routes.rb file to make sure the resource has been mapped (map.resources :users), maybe add a bit of code the link <%= link_to @story.user.login, user_path(@story.user) %>

Thanks much. That was the extra insight I needed. The error was actually in the routes file. The difference between ‘map.resource’ and ‘map.resources’.

Again, thanks!

Glad I could help :slight_smile: