Money-Rails Gem: How to Make a Picklist for All Currencies?
I am using a gem with money rails and want to show in my opinion a list of different currencies, but the code I have is Working.
I have my model Price
and fields in_cents
and currency
:
create_table :prices do |t|
t.integer :in_cents, default: 0, null: false
t.string :currency, default: 'USD', null: false
Now according to the Money gem and the Money-Rails docs I needed to do something like:
class Price < ActiveRecord::Base
monetize :in_cents, as: "amount", with_model_currency: :in_cents_currency
def all_currencies(hash)
hash.keys
end
Than my view with a simple gem form:
= f.input :currency, collection: all_currencies(Money::Currency.table)
= f.input :amount, required: false
But this gives me an error:
undefined method `all_currencies' for #<#<Class:0xd154124>:0xd15bab4>
Why?
PS
I want to show the ISO code and type name United States Dollar (USD)
.
+3
source to share
3 answers