Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I pass an id to a foreign controller?

Mark Webster asked in Rails

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

Reply

Hi Mark,

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

Reply

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.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.