Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Values based on Condition

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.

like image 328
ardavis Avatar asked Nov 12 '22 17:11

ardavis


1 Answers

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 .

like image 199
R Milushev Avatar answered Dec 21 '22 10:12

R Milushev