Created
June 13, 2017 11:27
-
-
Save CharlieHawker/d02fabcabbc4a4d5348bf3e938b58f39 to your computer and use it in GitHub Desktop.
create ransackers for monetized fields on an ActiveRecord object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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