On 24 August 2014 08:25, Jaimin Pandya <li...@ruby-forum.com> wrote: > Matt Jones wrote in post #1155588: >> On Wednesday, 20 August 2014 03:45:44 UTC-4, Ruby-Forum.com User wrote: >> You're going to need to figure out why @line_item.expensescounter is >> nil. >> Post the code here if you need help finding the problem. > >> Code of application_controller.rb: > > class ApplicationController < ActionController::Base > protect_from_forgery > include SessionsHelper > > private > def current_expensescounter > Expensescounter.find(session[:expensescounter_id]) > logger.info "expensescounter_id is > #{(session[:expensescounter_id])}"
With the logger.info line here you have changed what this function returns, as now it will return the result from logger.info, not from the find. Move that line above the find call, then put another logger call in the rescue. > rescue ActiveRecord::RecordNotFound > expensescounter = Expensescounter.create > session[:expensescounter_id] = expensescounter.id > expensescouter That should be expensescounter not expensescouter, but that would give a different error if it ran so I presume that line of code has never been executed. > end > end > > Any help would be appreciated. I am assuming that neither of the problems I have noted above is causing the actual problem (as I assume you put the logger call in to try and diagnose it. We went all round this last time you tried to ask this question a little time ago. You must show us the code where you set @line_item.expensescounter. The above code does not do that, it is just a private method of the controller that returns an Expensescounter object. If you do not understand what I am asking then please say so. 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 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%3D0gLtxfsUOH1-uXQQpO9CoR9HntSx-k_QSVjZDs8Qra1%3Dj%3DA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.