Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currency column type #137

Open
sunblaze opened this issue Dec 11, 2017 · 0 comments
Open

Currency column type #137

sunblaze opened this issue Dec 11, 2017 · 0 comments

Comments

@sunblaze
Copy link

A currency column type would be very useful to have in this gem. Here's what I've used in the core to get what I was looking for.

    class CurrencyType < ActiveRecord::Type::String
      def serialize(value)
        return value.iso_code if value.respond_to?(:iso_code)
        super
      end

      def cast(value)
        Money::Currency.new(value)
      end
    end
    attribute :base, CurrencyType.new
    attribute :counter, CurrencyType.new

Would be nice if the gem also registered the type so it could just be attribute :base, :currency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant