Ransack: Rails 5 params / ActionController::Parameters compatibility

Created on 16 Jun 2016  Â·  7Comments  Â·  Source: activerecord-hackery/ransack

ActionController::Parameters params[:q] doesn't return hash in Rails 5. see https://github.com/activerecord-hackery/ransack/blob/master/lib/ransack/search.rb#L19

# works in Rails 5
@q = Person.ransack(params[:q].to_unsafe_h)

Most helpful comment

Having the same issue... I tried to fix it using controller whitelists but it didn't appear to work. I'm looking at it in more detail now though.

@q = @instance.videos.ransack(search_params)

def search_params
    params.permit(:utf8, :commit, q: [:title_eq]).to_h
end

All 7 comments

Having the same issue... I tried to fix it using controller whitelists but it didn't appear to work. I'm looking at it in more detail now though.

@q = @instance.videos.ransack(search_params)

def search_params
    params.permit(:utf8, :commit, q: [:title_eq]).to_h
end

Same here!

Ransack master has been working with Rails 5 since a year and a half now:

gem 'ransack', github: 'activerecord-hackery/ransack'

Will make a new official release very soon.

@jonatack I do not know what's more using the master branch does not render the attribute_select

Hello @danieldocki, it sounds like you are reporting a different issue or regression. If so, would you please file a separate issue or pull request following the CONTRIBUTING Guide.

Progress on what -- could you be more specific, please? This issue was solved a year before it was filed, and is closed. The empty attributes_select was fixed as well.

On Tuesday, August 30, 2016, Gary [email protected] wrote:

Any progress?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/activerecord-hackery/ransack/issues/687#issuecomment-243502097,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACTbfNMfGavDAMMrrVUNsLpfDXoOsFXIks5qlF2XgaJpZM4I3GZL
.

I'm having problems with the Rails 5.0.0.1 version.
I created a new project to test and is not working.

<%= search_form_for @q do |f| %>
  <%= f.label :name %>
  <%= f.search_field :name %>
  <%= f.submit %>
<% end %>
def index
    @q = User.ransack(params[:q])
    @users = @q.result(distinct: true)
    puts @users
end

I believe it is in params:

Processing by UsersController#index as HTML
  Parameters: {"utf8"=>"✓", "q"=>{"name"=>"Gleydson"}, "commit"=>"Search"}
Was this page helpful?
0 / 5 - 0 ratings