logo       

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

RubyonRailsTalk

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


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

>
> On Jul 31, 6:18Âpm, Colin Law <clan...@xxxxxxxxxxxxxx> wrote:
>> 2009/7/31 seenu <desaise...@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
-~----------~----~----~----~------~----~------~--~---

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise