0

尝试在 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
4

1 回答 1

1

由于它has_many介于 Merchant 和 Merchant 类别之间,因此您不能使用merchant_category. 应该是merchant_categories

于 2014-03-08T06:41:04.753 回答