activerecord-hackery / ransack_demo

A demo app using Ransack to create advanced search forms.

Home Page:http://ransack-demo.herokuapp.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compatibility with Rails 5 - attribute_fields

haslinger opened this issue · comments

I forked the demo and updated it to ransack_demo / Rails 5.

The application itself starts, but within the condition group after adding a condition, the attribute field dropdown is missing.

I tried to debug the issue, and found that within the attribute_fields helper the call to the search_fields method returns an empty string.
In the old version (Rails 3.x) the proper html string for the dropdown was returned.

Reason for my findings is that I have exactly the same issue updating my own application to Rails 5 (so it's not specific to the demo app).

Thanks @haslinger. Would you like to add a PR to update ransack_demo to Rails 5?

@jonatack Yes, will do so in a few mins.

To document the monkey patches I did to make it Rails 5 compatible:
They are all in the file
https://github.com/haslinger/ransack_demo/blob/rails5/config/initializers/ransack.rb

While the second one
self.attributes << attribute # if attribute.valid?
is basically a bad hack, I believe that the constants for ASC and DESC are truly missing in current Ransack.

Thanks. The missing ASC and DESC was fixed in this commit.

Closing in favor of the open issue in Ransack. Thanks again!