ruby on rails - How do I create a new attribute in a model? -
hi i'm new in ruby , rails , want create new attribute email model account. down below test new attribute. test copy of name attribute test figured working in similar way.
it "should have email field" @account.email = "email" @account = save_and_reload(@account) @account.email.should == "email" end
the thing i've done make test pass create email attribute in account model. , have manually inserted new column email in database account table.
here part of account model code i've inserted email attribute:
class account < activerecord::base attr_accessible :name, :logo, :account_preference_attributes,:email
when run test error nomethoderror in 'account should have email field'
undefined method `email=' #<account:0xb6468ca8>
so how create new attribute in model?
you have create migration add email column table , run rake db:migrate
class addssl < activerecord::migration def self.up add_column :accounts, :email, :string end def self.down remove_column :accounts,:email end end
also remove email column table have manually added.
Comments
Post a Comment