Skip to content

Instantly share code, notes, and snippets.

@dnch
Created December 22, 2011 22:40
Show Gist options
  • Save dnch/1512171 to your computer and use it in GitHub Desktop.
Save dnch/1512171 to your computer and use it in GitHub Desktop.
class FoosController < AbstractController::Base
def update
@foo = Foo.find(params[:id])
# If our changed object saves...
if @foo.update_attributes(params[:attributes])
# Now, we check for changes. In some situations, we might
# use @foo.notify_changed? but given that update_attributes
# clobbers the dirty state of your instance, we need to
# use previous_changes
if @foo.previous_changes[:notify]
# flash?
redirect_to @foo, notice: "Flash message in flash[:notice]"
else
# do something else?
end
# Otherwise, handle our error
else
render action: "edit"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment