SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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: </p>
    18: <p class="submitted_by">
    19: Submitted by:
    20: <span><%= link_to @story.user.login, @story.user %></span>
    21: </p>
    22: <p>
    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'

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Location
    Cleveland, OH
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 <&#37;= link_to @story.user.login, user_path(@story.user) %>

  3. #3
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Location
    Cleveland, OH
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad I could help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •