Sometimes error messages can be meaningful. The error says Cannot
redirect to nil, so it may be that
@line_item.expensescounter is nil.
Simple debugging can be performed using Logger.info, which inserts
into the log file (eg log/development.log), so you can confirm this by
inserting, before the problem line
Logger.info( "expensescounter is: #{@line_item.expensescounter}"
If it is nil, if you cannot see the problem, you can put additional
logs in to home in on the problem.
Also in the log file you will find useful information showing the
parameters being passed into the action.
Simple debugging can be performed using Logger.info, which inserts
into the log file (eg log/development.log), so you can confirm this by
inserting, before the problem line
Logger.info( "expensescounter is: #{@line_item.expensescounter}"
I used logger.info for debugging and it insert in development.log file
that @line_item.expensescounter is nil.
If it is nil, if you cannot see the problem, you can put additional
logs in to home in on the problem.
Also in the log file you will find useful information showing the
parameters being passed into the action.
I have attached development.log file(productionlog.odt) in my question.
By working out why it is nil. It is called debugging. Have a look
where you setup that value and if necessary put more logging in till
you see where the problem is.
By working out why it is nil. It is called debugging. Have a look
where you setup that value and if necessary put more logging in till
you see where the problem is.
I will find out why it is nil.
Thank you for your help.
As was suggested before, use logging to see what is actually happening. When you're starting without a clue, log after every line to see where things become different than what you expect.
As was suggested before, use logging to see what is actually happening.
When you're starting without a clue, log after every line to see where
things become different than what you expect.
I used logging to see what is actually happening. I found
expensescounter_id comes nil which is not my requirement.
expensescounter_id should have some value. Could you help me in this?
You have not shown us the code where you set expensescounter_id, or
the code that you expect that value to be set. You have shown us the
code where expenses_counter.id would be setup but presumably
expensescounter_id is an attribute of a different object.
You have not shown us the code where you set expensescounter_id, or
the code that you expect that value to be set. You have shown us the
code where expenses_counter.id would be setup but presumably
expensescounter_id is an attribute of a different object.
I following "Agile web development with rails 3.2" book.
Yes, expensescounter_id is an attribute.
I use that attribute in line_item.rb file like as follow:
class LineItem < ActiveRecord::Base
attr_accessible :quantity_id, :expensescounter_id
belongs_to :quantity
belongs_to :expensescounter
end
You have not shown us the code where you set expensescounter_id, or
the code that you expect that value to be set. You have shown us the
code where expenses_counter.id would be setup but presumably
expensescounter_id is an attribute of a different object.
I following "Agile web development with rails 3.2" book.
Yes, expensescounter_id is an attribute.
I use that attribute in line_item.rb file like as follow:
class LineItem < ActiveRecord::Base
attr_accessible :quantity_id, :expensescounter_id
belongs_to :quantity
belongs_to :expensescounter
end
expensescounter_id should be set when you add the expensescounter to
the lineitem. That is the code you need to debug, or show us.
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?
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:
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
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.