Here is the code for update in invoice controller:
def update
@invoice = Invoice.find(params[:id])
if @invoice.approved_by_corp_head_changed?
@invoice.approve_date_corp_head = Time.now
@invoice.corp_head_id = session[:user_id]
end
if @invoice.update_attributes(params[:invoice], :as => :roles_update)
redirect_to URI.escape("/view_handler?index=0&msg=Updated")
else
flash.now[:error] = 'Not saved!'
render 'edit'
end
end
Value of approved_by_corp_head was saved correctly. The problem is that if @invoice.approved_by_corp_head_changed?
was always false and the IF loop never gets executed. In rails console, the @invoice.approved_by_corp_head_changed? is true if the value is changed. What could be wrong here? Thanks so much.