-
Notifications
You must be signed in to change notification settings - Fork 389
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
Setting default currency to gbp
breaks gem
#413
Comments
👍 I just hit this exact issue on a Rails 4.0.13 application I'm working on. |
I'll take a look at that. Can you guys provide a bit more details on your setup? Schema, |
Sure. I'll get you something to reproduce it tonight. |
For what it's worth, I solved this by doing this instead in my initializer:
|
@bacrossland thanks a lot! |
@dvdhsu I'll check that myself as well, thanks |
@antstorm I'm still working on a reproducible case. When just set up a clean rails install with only money and money_rails in the gem, I didn't have the issue. I suspect there is another gem in my Gemfile that is interfering with the load of money and money_rails when the currency is switched to GBP. I'll post more of my findings when I have it. |
@bacrossland can you share your |
Here's mine -- maybe there's some intersection.
|
Sorry, I was out sick for the last 5 days. Here is my Gemfile.
|
@dvdhsu @bacrossland I think I know what the problem is. Setting the default currency to GBP results in config.amount_column = { postfix: '_cents' } |
Thanks @antstorm. I just tried your fix and still the same error occurred. You are correct that money_rails is looking for a DB column with the name The issue will happen when you try to switch the default_currency to any currency that has a different subunit than the one you originally created the DB schema using. GBP, GEL, GHS, etc. can not switch between each other let alone USD. USD to EUR worked because they each have a subunit of Cents (DB column of |
@bacrossland yep, although you can get away with making sure you change the MoneyRails.configure do |config|
config.default_currency = :gbp
config.amount_column = { postfix: '_cents' }
end It definitely requires a fix, which I will work on, but for now I think you can get away with this solution. Please tell me if that worked. |
@antstorm that worked. I was trying to set the column before the currency which is why it didn't work for me. Thanks! |
@bacrossland great! I'll put together a fix for the config order issue as well as a more descriptive error for when it's unable to find a column |
👍 |
I will also fix order issue for configuration later, but with #441 in you should be getting a comprehensive error when amount column could not be inferred |
In my config/initializers/money.rb:
When I try to set balance, the money-rails gem seems to be unitialized, and Rails tells me that
balance=
is not a defined method on my User object.When I switch the default currency to either
:eur
or:usd
, it works fine.I'm on Rails 5, beta 1.
The text was updated successfully, but these errors were encountered: