Hi there!

I experienced an issue with routing.

Basically, I'm trying to follow step-by-step the Rails' official guides
process for what concerns the nested routing.
So, I have Newspapers that has_many :ads , and :ads belongs to
:newspaper .

What I did was simply trying to obtain an URL like this:

http://localhost/newspapers/1/ads/1

but when I set routes.rb in this way:

resources :newspapers do
resources :ads
end

(as specified in Rails' guides), I obtain this error :


No route matches {:controller=>"ads", :action=>"show", :id=>#<Ad id: 1,
product: "an ad", created_at: "2011-11-10 19:54:12", updated_at:
"2011-11-10 19:55:06", newspaper_id: 1>}

Am I forgetting something?

Cheers,
Leo

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Dave Aronson at Nov 10, 2011 at 8:59 pm

    On Thu, Nov 10, 2011 at 15:26, Leo M. wrote:

    I have Newspapers that has_many :ads , and :ads belongs to
    :newspaper . ...
    http://localhost/newspapers/1/ads/1 ...
    resources :newspapers do
    resources :ads
    end ...
    No route matches {:controller=>"ads", :action=>"show", :id=>#<Ad id: 1,
    product: "an ad", created_at: "2011-11-10 19:54:12", updated_at:
    "2011-11-10 19:55:06", newspaper_id: 1>}

    Am I forgetting something?
    The route barf should have said :id=>"1" (or at least some number). I
    think you're somehow passing it a whole ad, rather than an ad ID.
    Otherwise we wouldn't have the other column in there, like product and
    the timestamps. The big question is, what did you do to create this
    error? Did you point a browser at the URL shown above (presumably
    after telling it to use port 3000)? Or some other, in which case what
    was it? Or was it an automated test, in which case "post teh codez
    pls"?

    If it was via a different URL, then we'll probably need to look at
    that URL's controller and maybe view.

    -Dave

    --
    LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern languages.
    Where: Northern Virginia, Washington DC (near Orange Line), and remote work.
    See: davearonson.com (main) * codosaur.us (code) * dare2xl.com (excellence).
    Specialization is for insects. (Heinlein) - Have Pun, Will Babble! (Aronson)

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Radhames brito at Nov 10, 2011 at 9:15 pm

    On Thu, Nov 10, 2011 at 4:26 PM, Leo M. wrote:

    Hi there!

    I experienced an issue with routing.

    Basically, I'm trying to follow step-by-step the Rails' official guides
    process for what concerns the nested routing.
    So, I have Newspapers that has_many :ads , and :ads belongs to
    :newspaper .

    What I did was simply trying to obtain an URL like this:

    http://localhost/newspapers/1/ads/1

    but when I set routes.rb in this way:

    resources :newspapers do
    resources :ads
    end

    (as specified in Rails' guides), I obtain this error :


    No route matches {:controller=>"ads", :action=>"show", :id=>#<Ad id: 1,
    product: "an ad", created_at: "2011-11-10 19:54:12", updated_at:
    "2011-11-10 19:55:06", newspaper_id: 1>}

    Am I forgetting something?

    post the code on the link_to helper to see how you are trying to access
    that path

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 10, '11 at 8:26p
activeNov 10, '11 at 9:15p
posts3
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase