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