Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Created March 27, 2013 23:50
Show Gist options
  • Select an option

  • Save j-mcnally/5259239 to your computer and use it in GitHub Desktop.

Select an option

Save j-mcnally/5259239 to your computer and use it in GitHub Desktop.
Handle your create and update code in one method
alias :create, :do_save
alias :update, :do_save
def do_save
@model = Model.find_or_initialize_by_id(params[:id])
if @model.persisted?
#create specific code
end
@model.update_attributes(params[:model])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment