Skip to content

Recent scopes addition broke #search(params[:q]) API #403

@ohaibbq

Description

@ohaibbq

It appears that the recent additions of adding scopes (which is great!) doesn't support the API of passing unmodified ActionController::Parameters.

Assuming:

class Person < ActiveRecord::Base
    scope :domestic, -> { where(country: 'US') }
    def self.ransackable_scopes(auth_object=nil); [:domestic]; end
end

Here's a few examples:

Person.search(domestic: true) # scopes just perfectly

Form helper using a hidden input

<%= f.hidden_field :domestic %>

If the input value is set to true, it is deserialized from the request as "true".

Calling Person.search(params[:q]) will raise ArgumentError: wrong number of arguments (1 for 0) as Ransack tries to pass "true" to the scope.

If the hidden value is set to "", Ransack skips applying the scope.

For now, we are able to manually deserialize these parameters in to the correct values, but just wanted to give you a heads up.

I should be able to look in to ransack's code some more this weekend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions