Skip to content

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

@matenia

Description

@matenia

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions