Ruby on Rails Tuesday, August 5, 2014

> I still don't see the code that adds @expensescounter to @line_item.
> Can you point to a particular line that does this?

That code is not used.

What i done is that i add expense column to line_items table. Then i
generate migration like as follow:

" rails generate migration combine_items_in_expensescounter "

In migration file i used following code:

class CombineItemsInExpensescounter < ActiveRecord::Migration
def up
Expensescounter.all.each do |expensescounter|
sums =
expensescounter.line_items.group(:quantity_id).sum(:expense)
sums.each do |quantity_id, expense|
if expense > 1

expensescounter.line_items.where(quantity_id:quantity_id).delete_all

item = expensescounter.line_items.build(quantity_id:
quantity_id)
item.expense = expense
item.save!
end
end
end
end

def down
end
end

This was working. I can able to add quantity to expensescounter and one
by one price of that quantity add in that.

BUT when i was create association between user and expensescounter model
this problem occur.

--
Posted via http://www.ruby-forum.com/.

--
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a8ab68ce0c6aec174a64fb8e22a8e768%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment