Search code examples
ruby-on-railskaminariransackruby-on-rails-4.1

Ransack with kaminari on rails 4.1 error with empty search string


I am using Ransack simple search with kaminari for pagination successfully on rails 4.0.4. I have upgraded rails with this project to 4.1.0, which is the only change, and now if I search without entering any inputs in the search form I get: undefined method `delete_if' for "":String This previously worked with the earlier version of rails!

@q = HouseDesign.search(params[:q])
@house_designs = @q.result
@q.sorts = 'price asc' if @q.sorts.empty?
@house_designs = @house_designs.page params[:page] 

url when it errors note

q=?&page=2&q=&utf8=✓  4.1.0

url when successful

?&page=2&utf8=✓ 4.0.4

This is only my second project in rails so I could be missing something but I have spent all day searching to no avail.


Solution

  • Looks like this was fixed in this commit: https://github.com/activerecord-hackery/ransack/commit/71021b558b26d31e4b3b4a03cd595efd35ad25c4

    Try running the rails-4.1 branch. It's working for me with Rails 4.1 with this in my Gemfile:

    gem 'ransack', :github => "activerecord-hackery/ransack", :branch => "rails-4.1"