播种时未定义的方法

时间:2014-03-08 06:33:01

标签: ruby-on-rails undefined seeding

尝试在ROR中播种数据库时出现以下错误:

[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
rake aborted!
undefined method `merchant_category' for #<Merchant:0x227c12e0>
/home/boris/Desktop/Wholetail/db/seeds.rb:18:in `block in <top (required)>'
/home/boris/Desktop/Wholetail/db/seeds.rb:15:in `<top (required)>'
Tasks: TOP => db:seed

(通过使用--trace运行任务查看完整跟踪)

商家模特:

class Merchant < ActiveRecord::Base

    has_many :deals
    has_many :customers
    has_many :mmcs
    has_many :merchant_categories, through: :mmcs

    validates :merchant_name, presence: true
    validates :merchant_email, presence: true, uniqueness:true
    validates :merchant_phone, presence: true
    validates :merchant_address, presence: true
    validates :merchant_url, presence: true, uniqueness: true
    validates :merchant_category, presence: true

end

商家类别模型:

class MerchantCategory < ActiveRecord::Base
    has_many :mmcs
    has_many :merchants, through: :mmcs

    validates :merchant_category_name, presence: true, uniqueness: true

end

1 个答案:

答案 0 :(得分:1)

由于商家和商家类别之间的has_many,您无法使用merchant_category。它应该是merchant_categories