Rails: create two nested items in controller but only one shows in the view -
consider following:
customer.rb
module refinery class customer < refinery::core::basemodel has_many :users, :class_name => "refinery::user" accepts_nested_attributes_for :users end end end
user_decorator.rb
refinery::user.class_eval belongs_to :customer, :class_name => 'refinery::customer' end
customer_controller.rb
module refinery class userscontroller def new @customer = ::refinery::customer.new # tried using build here no sucess @owner = @customer.users.new @inputer = @customer.users.new # raise @customer.users.length.to_yaml => returns 2 works! end end end
new.html.erb
<%= form_for @customer |f| %> <% if @customer.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@customer.errors.count, "error") %> need corrected before continuing:</h2> <ul> <% @customer.errors.full_messages.each |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <!-- company fields here --> <%= fields_for :users |user| %> <div> <%= user.label :first_name %> <%= user.text_field :first_name %> </div> <div> <%= user.label :last_name %> <%= user.text_field :last_name %> </div> <!-- more user fields here etc --> <% end $> <% end %>
when view page 1 user shows up. ids fields also:
<div> <label for="users_last_name">last name</label> <input id="users_last_name" name="users[last_name]" size="30" type="text"> </div>
i think there should kind of index in there right? (i.e. 0, 1, 2 etc if iterating on array.
what doing wrong?
you missed
f.fields_for
just add , should work
Comments
Post a Comment