2011-12-04 31 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中的所有寶石。 –