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_id
to product form (productbelongs_to
user) 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 ...
You can use
accepts_nested_attributes_for
.In your form