edit action with nested forms

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

edit action with nested forms

fugee ohu
i have items, item_item_properties, and item_properties
items has many item_properties with the key item_type_id in both tables
the name value pairs are stored in item_item_properties
the problem i'm having is not all item_properties are showing up in the form
what makes the difference which one's show up and which one's don't I don't know

items_controller.rb

  def edit
        @item = Item.includes(:item_item_properties).find(params[:id])
        @item.item_properties.each do |ip|
              @item.item_item_properties.build(item_property_id: ip.id) unless @item.item_item_properties.find_by(item_property_id: ip.id)
        end
  end


_form.html.erb

            <%= f.fields_for :item, :item_item_properties do |iip| %>
                      <div class="item_item_property">
                          <% @item.item_item_properties.each do |item_item_property| %>
                                <tr><td><%= iip.label item_item_property.item_property.name %><td><%= iip.hidden_field :item_property_id, value: item_item_property.item_property_id %> <%= iip.text_field  :text_value, value: item_item_property.text_value %>
                         <% end %>
                      </div>
            <% end %>


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/d05a7c7b-b5b5-4c11-8bda-24573fcad0fd%40googlegroups.com.