Saggex
Saggex

Reputation: 3500

NameError for existing name

I get this NameError when executing my application.

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

It's somewhere in this code, but I don't understand it. I have my country_code, but It says it's inexistant.

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

Does anyone know how to fix this?

Upvotes: 0

Views: 78

Answers (1)

j-dexx
j-dexx

Reputation: 10416

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

You need to make the variables symbols

Upvotes: 5

Related Questions