Ruby on Rails Tuesday, August 5, 2014

> As I have already said you need to debug or show us the code where you
> tell the individual line item that it owns that particular
> expensescounter (or the code where you tell the expenses that it
> belongs to that particular line item, whichever way you do it).
>
> Presumably somewhere you have called current_expensescounter to create
> it, but then what have you done with it?

I have used current_expensescounter method in application_controller.rb
file.

Then current_expensescounter use in create method of
line_items_controller.rb file to add selected quantity to
expensescounter. like as follow:

def create
@expensescounter = current_expensescounter
quantity = Quantity.find(params[:quantity_id])
@line_item = @expensescounter.add_quantity(quantity.id)
@line_item.quantity = quantity
.
.
.
.
.
end

In above code i used add_quantity, that method i define in
expensescounter.rb file like as follow:

def add_quantity(quantity_id)
current_item = line_items.find_by_quantity_id(quantity_id)
if current_item
current_item.expense += 1
else
current_item = line_items.build(quantity_id: quantity_id)
end
current_item
end

--
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/f60c684a9475cefd353780bd7cdfae78%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment