Welcome Guest | Login

NoMethodError after deployment

Hi,

I am very new at programming RoR and hope you can help me on this issue. I got the following error after deployment (production.log):


Processing HomeController#index (for 70.79.130.36 at 2007-11-12 02:01:53) [GET]
 Session ID: 27122fd55a71d37498e1b1afedeb01fd
 Parameters: {"action"=>"index", "controller"=>"home"}


NoMethodError (undefined method `[]' for nil:NilClass):
   /home/railste/eventonrails2/app/controllers/home_controller.rb:12:in `list'
   /home/railste/eventonrails2/app/controllers/home_controller.rb:5:in `index'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:1101:in `send'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:1101:in `perform_action_without_filters'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/filters.rb:696:in `call_filters'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/filters.rb:688:in `perform_action_without_benchmark'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
   /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/rescue.rb:83:in `perform_action'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:435:in `send'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:435:in `process_without_filters'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/filters.rb:684:in `process_without_session_management_support'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/session_management.rb:114:in `process'
   /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/base.rb:334:in `process'
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/dispatcher.rb:41:in `dispatch'
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/fcgi_handler.rb:168:in `process_request'
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/fcgi_handler.rb:143:in `process_each_request!'
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/fcgi_handler.rb:109:in `with_signal_handler'
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/fcgi_handler.rb:142:in `process_each_request!'
   /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in `each_cgi'
   /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each'
   /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each_cgi'
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/fcgi_handler.rb:141:in `process_each_request!'
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/fcgi_handler.rb:55:in `process!'
   /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/fcgi_handler.rb:25:in `process!'
   dispatch.fcgi:24


The following code is "home_controller.rb":


class HomeController < ApplicationController
 before_filter :public_province
 
 def index
   list
   render :action => 'list'
 end
 
 def list    
   # today's events
   today_date = Time.now
   @today_event_pages, @today_events = paginate :events, :order => 'start_date', :conditions => ["is_approved = 1 and is_active = 1 and is_expired = 0 and province_id = ? and start_date < ? and end_date > ?", session[:province][:id], today_date, today_date], :per_page => 2    
 end
end


I am not sure if this is caused by the session, or filter, or database settings. Any comments is appreciated :-)

Thank you.


2007-11-12 02:19 AM

Your problem is in "session[:province][:id]"

do something like

@province = session[:province]
@id = @province.id

before the sql call and just put in @id instead of session[:province][:id].  

2007-11-12 09:56 AM

Hi William,

Thanks a lot for your fast reply.

I wonder why the same syntax works on my development box but not on production, it turns out I forgot to populate data in the province table in the production database :-)

But it is really great that people in this forum reply questions so fast and so helpful, thanks again!

Cheers!

2007-11-12 01:11 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up.