views:

310

answers:

1

It only happens in production, when we update some of the records through browser, the change was not saved. it does not seem to be a cache problem as we verified that the data in mysql was still the old data. However, the controller did get hit and flash message returned as if the change was made successfully.

However, we can make the change manually in rails console or mysql withhout any problem.

Any ideas why this is happening?

btw, we recently reconfigure the site to use SSL, it might have something to do with that.

+1  A: 

Is there anything that could've prevented the model from being saved?

One way to ensure that the attributes are set and the model is saved is to use the exception raising version which can help fix problems like this:

def update
  @model = Model.find(params[:id])

  @model.update_attributes(params[:model])

  redirect_to(model_path(@model))
end

This could be improved to a more reliable method:

def update
  @model = Model.find(params[:id])

  # Use exception-throwing update_attributes!
  @model.update_attributes!(params[:model])

  redirect_to(model_path(@model))

rescue ActiveRecord::RecordNotFound
  render(:partial => 'not_found')
rescue ActiveRecord::RecordInvalid
  # Delegate back to edit action, something's invalid
  edit

  render(:action => 'edit')
end

There are occasions where update_attributes may not successfully save.

If you can perform the same update on the same data with the same methods then that is peculiar.

tadman