Reputation: 283
I have a question on rails3 nested_form.
These are my two models:
class User
belongs_to :shop
accepts_nested_attributes_for :shop
end
class Shop
has_many :users
end
In my register view(i am using Devise):
form_for(resourse,:url => registration(resource_name)) do |f|
=f.fields_for :shop do |s|
=s.text_fields :name
but i get nothing for this form. What should i do?
Upvotes: 0
Views: 134
Reputation: 3785
You need to add some objects first to it. Use build method on model in controller.
Example:
@shop = Shop.new
3.times { @shop.users.build }
More informations at Railscasts. AJAX is used in second part of this video.
Upvotes: 2