Nesting a rails form on a show page-Collection of common programming errors

I have a has many through relationship between my user and a vehicle.

User has many Ownerships
User has many vehicles through Ownerships.

Ownerships belongs to User and Vehicle

Vehicle has many Ownerships
Vehicle has many Users through Ownerships

On the vehicle show page I would like to make a form that allows creation of a new user and at the same time builds the association between vehicle and user i.e. adds an entry in the ownerships model that populates the vehicle ID of the vehicle currently being viewed and the user id of the newly created user.

Ideally the page would redirect back to the same vehicle show page.

I have tried to do this myself and am able to create the associations (and redirect back correctly) on their own but not both.

When I try to add a user from the vehicle show page I am unable to pass the current vehicleid as a hidden field without errors such as unknown attribute vehicle_id.

Also would my user_controller differ if I plan to have a form on vehicle show and /user/new. Right now I am trying to read the current vehicle page inthe create method. This would fail every time from the user new page.

Originally posted 2013-11-09 23:06:09.