Rails nested Routing

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

On Thu, Nov 10, 2011 at 15:26, Leo M. [email protected] 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)

On Thu, Nov 10, 2011 at 4:26 PM, Leo M. [email protected] wrote:

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