logo       

[Rails] Re: NoMethodError (undefined method `[]' for nil:NilClass): msg#03241

RubyonRailsTalk

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


2009/7/31 seenu <desaiseenu@xxxxxxxxx>:
>
> 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
>

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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@xxxxxxxxxxxxxxxx
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Google Custom Search

News | Mail Home | sitemap | FAQ | advertise