On 5 August 2014 16:05, Jaimin Pandya <li...@ruby-forum.com> wrote: >> 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.
I don't understand you. The problem you originally posted was that in @line_item.expensescounter expensescounter was nil, with lineitem belongs to expensescounter. For that code to work you need to tell @line_item needs to know that it owns the expensescounter object. Where have you done that? Or are you now talking about a new problem that you have not fully described? If so then please start again, describe the problem carefully and show us the code that does not work (just the bit that does not work). By debugging you should have tied that down to just a few lines of code. Colin > > 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+unsubscr...@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. -- 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+unsubscr...@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/CAL%3D0gLvBvvnWH4somC3KxYyXDgsBuNLrQdEo9%2BQj73PEgW-rVA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.