Hi I’m new in ruby and rails and I want to create a new attribute email for the model Account.
Down below is the test for my new attribute. The test is a copy of the name attribute test but i figured that they will be working in a similar way.
it "should have a email field" do
@account.email = "email"
@account = save_and_reload(@account)
@account.email.should == "email"
end
The only thing I’ve done to make the test pass is to create a email attribute in the account model. And I have also manually inserted a new column email in the database account table.
Here is part of the account model code where I’ve inserted the email attribute:
class Account < ActiveRecord::Base
attr_accessible :name, :logo, :account_preference_attributes,:email
When i run the test I get the error NoMethodError in ‘Account should have a email field’
undefined method `email=' for #<Account:0xb6468ca8>
So how do I create a new attribute in the model?
You have to create a migration to add email column into the table and run rake db:migrate
Also remove the email column from the table that you have manually added.