0

執行我的應用程序時出現此問題NameError現有名稱的名稱錯誤

NameError in CountriesController#index 
undefined local variable or method `country_code' for Country(id: integer, name: string, country_code: string):Class 

這是什麼地方在此代碼,但我不明白。 我有我的國家代碼,但它說這是遙不可及的。

class Country < ActiveRecord::Base 
    validates country_code, presence: true 
    validates name, presence: true 
    has_and_belongs_to_many :groups 

有誰知道如何解決這個問題?

回答

5
class Country < ActiveRecord::Base 
validates :country_code, presence: true 
validates :name, presence: true 
has_and_belongs_to_many :groups 

你需要做的變量符號

+0

謝謝!適合我! – user3383458