Ruby on rails. Ransack search on money-rails Monetize attribute -
i having problems searching money-rails/monetized attribute using ransack. able search in cents. have model (gig) money attribute salary. can create model no problem with:
<%= form.input :salary %> which saves value in salary_cents column expected in gig model have:
monetize :salary_cents i can show salary in view with:
<%= @gig.salary %> the problem having searching field ransack. salary attribute null, , salary_cents attribute populated should be, means can search in cents.
for search using:
<%= f.search_field :salary_cents_gteq %> <%= f.search_field :salary_cents_lteq %> but search $30, have input 3000. there way of manipulating inputted data, multiplying 100, before sending search request? there easier ways missing?
i have searched , cannot find information on searching money fields ransack.
thanks in advance.
ransack's custom predicates saves day!
# config/initializers/ransack.rb ransack.configure |config| config.add_predicate 'gteq_euros', arel_predicate: 'gteq', formatter: proc { |v| v * 100 }, validator: proc { |v| v.present? } config.add_predicate 'lteq_euros', arel_predicate: 'lteq', formatter: proc { |v| v * 100 }, validator: proc { |v| v.present? } end once restart rails application ransack dollars / euros wanted:
<%= f.search_field :salary_cents_gteq_euros %> <%= f.search_field :salary_cents_lteq_euros %>
This comment has been removed by the author.
ReplyDeleteRUBY ON RAILS CUSTOM WEB APPLICATION SERVICES
ReplyDelete