6

I'm trying to get the money-rails gem working, and I'm having problems... >.<

Here's the product I have the appropriate columns on:

class ItemAttrVal < ActiveRecord::Base
  belongs_to :attr_name
  belongs_to :registry_item

  monetize :price_val_cents, :allow_nil => true
  #snip
end

I've run the migration, and the appropriate columns are there (price_val_cents, and price_val_currency).

I've got the gem in my Gemfile, and have run bundle install successfully.

When I do ItemAttrVal.new, I get this as the first line of the error message:

NoMethodError: undefined method `monetize' for #<Class:0x007fb489c759d0>

Could somebody help point out to me what simple thing I've missed? I haven't included it anywhere as a require (apart from my Gemfile), but I didn't think that was needed...

Thanks!

5
  • 10
    Have you restarted your console or server since adding the gem? Mar 2, 2013 at 15:35
  • 1
    Ok... That's really embarrassing... Restarted, and it worked! I thought that doing a reload! in the console was enough to at least get the console going?
    – Jty.tan
    Mar 2, 2013 at 15:37
  • I don't know exactly how reload! works, but this sort of makes sense because it doesn't reload the entire environment. Otherwise it would be really slow, which it's not. Since gems are loaded when the environment loads, reload! would not require any new gems that you added. Mar 2, 2013 at 15:53
  • 1
    I had the same problem, even after reloading. I had to kill spring and It worked.
    – Lomefin
    Jul 1, 2016 at 16:57
  • Same here- spring restart needed
    – Steve
    Feb 12, 2021 at 12:51

1 Answer 1

3

Based on Peter Brown's comment, you should restart the console whenever a new gem is added, or when environment variable is added or modified. Just exit and start it again, rebooting the server is also recommended.

Sometimes the problem persists, even after restart. In that case try to kill the spring server so you are starting completely fresh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.