Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

params[:search][:order] error -- "NoMethodError: undefined method `to_sym' for nil:NilClass" #160

Open
matenia opened this issue Jan 29, 2013 · 1 comment

Comments

@matenia
Copy link

matenia commented Jan 29, 2013

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.

@matenia
Copy link
Author

matenia commented Jan 29, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant