Skip to main content

How do I pass an id to a foreign controller?

Rails • Asked by Mark Webster

A very basic question I know, but I'm really struggling. If I use a link_to with the current controller's path then I get the id as a parameter but if I instead use a path to a different controller then I get a format instead.

So from the same view I get the following paths generated by the team show view:

team/2/add/ and player/add.2

TIA

MarkW


Hi Mark,

Can you post your routes and the link_to you're using?


Hi Mark, I'm with Jacob. If you could show the code that would be great.

Also, what are you trying to do? Do you have a single page with multiple objects executing different types of CRUD functionality? If thats the case then perhaps you should use a view object that is a single model that represents all the models on that page. That way you can maintain RESTful routes and not have to try and share object id's accross controllers.

I'm sure Chris has some content around executing this kind of strategy. If not, I'm happy to share some additional context if need be.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.