searchlogic
searchlogic copied to clipboard
params[:search][:order] error -- "NoMethodError: undefined method `to_sym' for nil:NilClass"
Hi,
I have the following in my controller
@search = Company.search(params[:search])
and this in my view
= order @search, :by => :name
The link generates the right query, however the destination page returns an error. Passing in the same options within a console yields the following:
>> Company.search(:order => 'ascend_by_name')
NoMethodError: undefined method `to_sym' for nil:NilClass
I'm running a rails 2.3.16 app using ruby 1.9.2p318. Is this a problem with my syntax (I'm pretty sure I followed everything in the instructions)
Here's the stack trace from the console ..
>> Company.search(:order => 'ascend_by_name')
NoMethodError: undefined method `to_sym' for nil:NilClass
from gems/activesupport-2.3.16/lib/active_support/whiny_nil.rb:52:in `method_missing'
from gems/searchlogic-2.5.8/lib/searchlogic/active_record/named_scope_tools.rb:16:in `named_scope_options'
from gems/searchlogic-2.5.8/lib/searchlogic/named_scopes/alias_scope.rb:54:in `named_scope_options'
from gems/searchlogic-2.5.8/lib/searchlogic/named_scopes/or_conditions.rb:14:in `named_scope_options'
from gems/searchlogic-2.5.8/lib/searchlogic/search/scopes.rb:15:in `scope_options'
from gems/searchlogic-2.5.8/lib/searchlogic/search/method_missing.rb:80:in `cast_type'
from gems/searchlogic-2.5.8/lib/searchlogic/search/method_missing.rb:22:in `method_missing'
from gems/searchlogic-2.5.8/lib/searchlogic/search/conditions.rb:19:in `block in conditions='
from gems/searchlogic-2.5.8/lib/searchlogic/search/conditions.rb:15:in `each'
from gems/searchlogic-2.5.8/lib/searchlogic/search/conditions.rb:15:in `conditions='
from gems/searchlogic-2.5.8/lib/searchlogic/search/date_parts.rb:19:in `conditions='
from gems/searchlogic-2.5.8/lib/searchlogic/search/base.rb:18:in `initialize'
from gems/searchlogic-2.5.8/lib/searchlogic/search/implementation.rb:10:in `new'
from gems/searchlogic-2.5.8/lib/searchlogic/search/implementation.rb:10:in `searchlogic'
from (irb):1
from ruby-1.9.2-p318/bin/irb:16:in `<main>'
>>
Am I doing something wrong? Thanks for your help.
It turns out that it doesn't like the order param being passed into the search method straight off.
I worked around this by changing my controller to read
@search = Company.order('').search(params[:search])
It kinda still feels like a hack. I would like to get some feedback on this if possible.
Thanks again,
- m