I am using the Ransack gem in my Rails application and it works great. My current issue is validation. This is essentially a two part question.
How can I add validations to the value field based on the condition. I.E. if the Year is the selected attribute, how can I change the value text box to be a select box with a list of years?
Also custom things like, if the condition is set to be a "Congressional District", I need the ability to check that the value is only 3 characters long with the first two being a state abbreviation.
It seems there is a pull request to add this valuable feature to the gem , we hope it will happen . Here is the description about the changes (quote from the GitHub discussion,dated 15 days ago):
Would just like to confirm that this is still a useful feature for us, but another approach would be to explicitly specify a good default order in lib/ransack/constants.rb. For example, here's the order we've decided on:
:cont, :not_cont, :blank, :present, :start, :not_start, :end, :not_end,
:true, :false, :eq, :not_eq, :lt, :gt, :lteq, :gteq, :null, :not_null,
:in, :not_in, :matches, :does_not_match
We're filtering predicates based on column type (string, integer, date, etc.), so this ordering sets good default values for each type.
EDIT : Here is an interesting solution on creating facets and filters with Ransack .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With