I think you not should do that. If you store price in products table, why 
you are store same thing in another table?

среда, 7 октября 2015 г., 8:57:00 UTC+3 пользователь peter williams написал:
>
> Hi people,
>
>
> i'm new to rails and have difficulties in actively using the model 
> relationships.
> I'm building an onlinestore with rails 4.2.4 following the book agile 
> development with rails 4.
> The asignment is to create a migration that copies the product price to 
> the line item.
>
> Class Product < ActiveRecord::Base
>
>     has_many :line_items
>
> Class LineItem < ActiveRecord::Base (is a jointable between product and 
> cart)
>
>    belongs_to :product
>
> My question is how do i instruct rails to copy an attribute from one model 
> to the other (in this case product.price to line_item.price)
>
>  I understand that the belongs_to and has_many methods bring in new 
> methods when called.
> e.g
> @line_item = @product.line_items
> I somehow can't make pratical use of this knowledge!! What really confuses 
> me is these are instance_variable 
> of the models but when it comes to use the author has been using the 
> tablenames
>  eg :line_items, :products etc how i'm i supposed to copy the 
> attribute_price from product using instance_variables?
>
> My migration for the new added price column to LineItem model
>
>   class AddPriceToLineItem < ActiveRecord::Migration
>     def up
>        add_column :line_items, :price, :decimal, precision: 8, scale: 2
>     end
>   end
>
> If the question is not clear just let me whats confusing. 
>
> Thanks for help
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/72425246-6fea-489d-a758-7aead6a74d1d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to