Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Product model ###
- class Product < ActiveRecord::Base
- has_one :line_item, :foreign_key => 'item_id', :conditions => {:kind => 2}
- validates_presence_of :kind, :description
- def price
- line_item.price
- end
- def line_item_update_attributes=(line_item_attributes)
- line_item_attributes.each do |attributes|
- line_item.update_attributes(attributes.last)
- end
- end
- end
- ### View for product ###
- <h2>Editing product</h2>
- <%= error_messages_for :product %>
- <% form_for(@product) do |f| %>
- <p>
- <b>Kind of Product</b><br />
- <%= f.text_field :kind %>
- </p>
- <p>
- <b>Description</b><br />
- <%= f.text_field :description %>
- </p>
- <p>
- <b>Price</b><br />
- <% fields_for "product[line_item_update_attributes][]", @product.line_item do |lif| %>
- <%= lif.text_field :price %>
- <% end %>
- </p>
- <p>
- <%= f.submit "Update" %>
- </p>
- <% end %>
- <%= link_to 'Show', @product %> |
- <%= link_to 'Back', products_path %>
Add Comment
Please, Sign In to add comment