In my view page, i am using form_tag to create a form which will pass a string of ids from a hidden field to the controller code.
In my controller code, i am looping through an array of ids to update each record containing that id in the Expression table. But the code below does not seem to work.
I would really appreciate it if somebody could give me some suggestion regarding what is wrong with the code below.
def update_expression
@emi_ids_array = params[:emi_ids].split(/,/)
@sub_id = params[:sub_id]
@emi_ids_array.each do |emi_id|
@existing_exp = Expression.find(:first, :conditions => [ "EXT_EMI_ID = ? and EXT_SUB_FK = ?", emi_id, @sub_id])
@expression = @existing_exp.update_attributes(
:EXT_SUB_FK => @sub_id,
:EXT_PRESENCE => "present",
:EXT_STRENGTH => "weak",
:EXT_EMI_ID => emi_id
)
end
end
Found a temporary solution. ‘update_attributes’ does not seem to work, so i opted for ‘update_all’ attribute
Hopefully, it might be useful to someone else