Brenda
Brenda

Reputation: 373

Using money_column gem with rails

I'm a rails noob... using Rails 3.1

I'm trying to use the money_column gem. I installed the gem, added to my gemfile, bundle install. I set up a Product model like the example.

My Product model is:

class Product < ActiveRecord::Base

  belongs_to :product_category
  attr_accessible :sku, :name, :description, :price, :available, :product_category_id
  money_column :price

end

I created some seed data in seeds.rb. When I run rake db:seed, though, I'm getting an error:

rake aborted!
undefined method `money_column' for #<Class:0x007fccbd26e468>

Have I missed something in installing money_column?

Upvotes: 4

Views: 702

Answers (1)

David Grayson
David Grayson

Reputation: 87516

I looked at the source code of that gem and I think it would work if you changed your model to this:

require 'money'
require 'money_column'

class Product < ActiveRecord::Base
  include MoneyColumn

  belongs_to :product_category
  attr_accessible :sku, :name, :description, :price, :available, :product_category_id
  money_column :price

end

Also, are you sure you are using the right gem? The official money_column gem on rubygems.org is this one: https://github.com/chargify/money_column

Upvotes: 2

Related Questions