On 20 August 2014 08:44, Jaimin Pandya <[email protected]> wrote:
> ...
>>>After creating association, when I click on "Add to count" button, I got 
>>>error
> like:
>
> ActionController::ActionControllerError (Cannot redirect to nil!):
>
> app/controllers/line_items_controller.rb:54:in `block (2 levels) in
> create'
>
> app/controllers/line_items_controller.rb:51:in `create'
>
>>> Code of line_items_controller.rb :
>
> def create
>  @expensescounter = current_expensescounter
>  quantity = Quantity.find(params[:quantity_id])
>  @line_item = @expensescounter.add_quantity(quantity.id)
>  @line_item.quantity = quantity
>
>  respond_to do |format|    #line no. : 51
>   if @line_item.save
>    format.html { redirect_to @line_item.expensescounter }  #line no. :
> 54
> .
> end
>
> How can I solve this problem?

By doing some debugging.  The error indicates that
@lineitem.expensescounter is nil (the clue is that it says cannot
redirect to nil) so you must find why this is the case.  Look in your
code to see where you set that up and work out why it is nil.  A
simple way of debugging to to insert lines like
logger.info( some_expression )
which will insert text into development.log (and in the server
window).  You can use that to look at values and work out what is
going wrong.

Colin

-- 
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/CAL%3D0gLsG7iq_N-wH5G-hwtoJ4zEfbjSSZBJ%2Bgv17ymii90R-rQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to