2011-12-04 34 views
4

使用money_column宝石我是小白的轨道...使用Rails 3.1与轨道

我试图使用money_column gem。我安装了gem,添加到我的gemfile,捆绑安装。我设置了一个像示例一样的产品模型。

我的产品型号是:

class Product < ActiveRecord::Base 

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

end 

我在seeds.rb创建了一些种子数据。但是,当我运行rake db:seed时,出现错误:

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

我在安装money_column时错过了什么吗?

+0

我会建议看看钱宝石。它处理金钱,货币和交换*非常*好。 https://github.com/RubyMoney/money –

回答

2

我看着那个宝石的源代码,我想如果你改变了你的模型,这会工作:

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 

另外,你确定你使用的是正确的宝石? official money_column gem on rubygems.org是这一个: https://github.com/chargify/money_column

+0

啊,我明白了,必须添加'require'。说得通。是否有一些自动的方法来知道某个特定宝石需要什么?是的,你是对的,我正在看github上的错误库。 – Brenda

+0

通常你只需要'需要gem_name',但这对于这个宝石来说不够好。有一些Bundler命令(可能是'Bundler.require'),它将需要Gemfile中的所有宝石。 –