Skip to content

Instantly share code, notes, and snippets.

@CharlieHawker
Created June 13, 2017 11:27
Show Gist options
  • Save CharlieHawker/d02fabcabbc4a4d5348bf3e938b58f39 to your computer and use it in GitHub Desktop.
Save CharlieHawker/d02fabcabbc4a4d5348bf3e938b58f39 to your computer and use it in GitHub Desktop.
create ransackers for monetized fields on an ActiveRecord object
class ExampleMonetizedProduct < ApplicationRecord
monetize :price
monetize :rrp
monetized_attributes.each do |attribute, field|
ransacker :"#{attribute}", formatter: proc { |v| v.to_f * 100 } do |object|
object.table[:"#{field}"]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment