ernie/ransack — Issue #45: Compound ransacker
Author: glebm
Created: 2011-12-12 18:36:52+00:00
State: open

Hi!

How do I create a ransacker that depends on two arguments?

Example:

I want to search by `max_price` based on `max_price_amount` and `max_price_currency`.

I tried the following

ransacker :max_price, args: [:max_price_amount, :max_price_currency] do |price_per_hour, currency|
usd_cents = Money.new(price_per_hour.to_i * currency.subunit_to_unit, currency).exchange_to(:usd).cents
Arel::Nodes::InfixOperation.new('<=', parent.table[:price_per_hour_usd_cents], usd_cents)
end

And in the view

= f.text_field :max_price_amount
= currency_select_tag 'q[max_price_currency]', current_currency.code

But that generates:

undefined method `max_price_amount' for #

How is it meant to be done?