加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 使用money_column gem和rails

发布时间:2020-12-17 02:12:27 所属栏目:百科 来源:网络整理
导读:我是一个rails noob …使用Rails 3.1 我正在尝试使用money_column gem.我安装了gem,添加到我的gemfile,bundle install.我设置了一个类似于示例的Product模型. 我的产品型号是: class Product ActiveRecord::Base belongs_to :product_category attr_accessi
我是一个rails noob …使用Rails 3.1

我正在尝试使用money_column gem.我安装了gem,添加到我的gemfile,bundle install.我设置了一个类似于示例的Product模型.

我的产品型号是:

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时遗漏了什么吗?

解决方法

我查看了该gem的源代码,我认为如果你将模型更改为:

require 'money'
require 'money_column'

class Product < ActiveRecord::Base
  include MoneyColumn

  belongs_to :product_category
  attr_accessible :sku,:product_category_id
  money_column :price

end

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读