NoMethodError (undefined method `[]' for nil:NilClass)

Hi everyone this is the error that's been killing me, please tell where i am missing. I have upgraded my rails version from 1.2.3 to 2.3.2 and have installed active_scaffold plugin, since then this error started which was not there in older version.

This is the log output:

Processing AccountController#consumer_home (for 122.167.8.236 at 2009-07-31 09:02:22) [GET]

NoMethodError (undefined method `' for nil:NilClass):   app/controllers/account_controller.rb:566:in `paginate_by_sql'   app/controllers/account_controller.rb:623:in `consumer_home' Rendering /home/v8354a/public_html/projectbidding/public/500.html (500 Internal Server Error)

I have paginate_by_sql function in application_controller.rb file which is shown below will call Paginator class.

def paginate_by_sql(model, sql, per_page, options={})       if options[:count]         if options[:count].is_a? Integer           total = options[:count]         else           total = model.count_by_sql(options[:count])         end       else         total = model.count_by_sql_wrapping_select_query(sql)       end       object_pages = Paginator.new self, total, per_page, @params ['page']       objects = model.find_by_sql_with_limit(sql, object_pages.current.to_sql[1], per_page)       return [object_pages, objects]   end

Please help

You have not told us which is line 566 which is where the error is. Looking at the code though I guess it is one of the lines containing options[:count] or maybe @params['page']. The error is undefined method `' for nil:NilClass which would suggest that maybe options or params is not set. If you can't see the problem by inspecting the code you could try using ruby-debug to break in at the appropriate point and have a look at what is going on. The rails guide on testing applications is good.

Colin

this is the call i am making on line 566: @auction_pages = paginate_by_sql (Auction, auctions_query, 10, '')

this is the call i am making on line 566: @auction_pages = paginate_by_sql (Auction, auctions_query, 10, '')

Are you sure? From the trace I would have expected line 566 of account_controller.rb to have been in the function paginate_by_sql and the call to paginate_by_sql to be at line 623 (in consumer_home).

Whatever the answer to that however, I suggest you have a look at the last parameter of the call, is that an empty string? The function appears to be expecting a hash. Though I am not sure whether that would give the error seen.

Did you try using the debugger?

By the way I believe that top posting is rather frowned on in this list.

Colin