Reputation: 2985
The two codes below are for updating the database.
The first version, which uses the 'update_attributes' property is not working
@existing_exp = Emiexperiment.find(:first, :conditions => [ "EMI_COM_ID = ? and EMI_SUB_FK = ?", "EMI_999", "7789"])
@existing_exp.update_attributes(
:EMI_STATUS => "present",
:EMI_ADD_STATUS => "weak"
)
However, the code below, which uses the 'update_All' attribute seems to work great.
Emiexperiment.update_all "EMI_STATUS = 'present', EMI_ADD_STATUS = 'moderate'", ["EMI_COM_ID = ? and EMI_SUB_FK = ?", "EMI_999", "7789"]
Here is the class code for Emiexpression:
class Emiexperiment < ActiveRecord::Base
set_table_name "EMI_EXPERIMENT"
set_primary_key "EMI_OID"
attr_accessible :EMI_STATUS, :EMI_ADD_STATUS, :EMI_COM_ID, :EMI_SUB_FK
belongs_to :sub, :foreign_key => "EMI_SUB_FK"
end
I am confused as to why this is so.
I am not using any validation in my 'Emiexperiment' model.
Any hint on this is most appreciated. Many many thanks for your help :)
Upvotes: 2
Views: 1011
Reputation: 96454
You may want attr_accessor
for those fields. attr_accessor
is a ruby method that makes a getter and a setter.
attr_accessible
is a Rails method that allows you to pass in values to a mass assignment:, e.g. update_attributes(attrs)
.
Upvotes: 1