I have 2 models:
brand
has_many :products
product
belongs_to :brand
In my view (show_brand.html.erb), i displaying all information about brand using @brand.name ....
I want to create form for product that belongs_to brand i'm displaying information about.
Something like:
form_for(@brand.products) ...
- How can i preform that?
- How can i attach
user_idto product form (productbelongs_touser) without adding it in controller manually
NOTICE: About first item in my list, i know that it can be done by upgrading routes to nested and passing array with main object and association object. But if there is another way of doing that? Without modifying routes.rb and ...
For question 1, you can use "nested form". Please check below link. http://railscasts.com/episodes/196-nested-model-form-part-1?view=asciicast
For question 2, even though you set user_id in "product form", you still have to do some check in your controller/model in case any undesired value is set to user_id. So the better way is you set it yourself at backend.