Created
March 27, 2013 23:50
-
-
Save j-mcnally/5259239 to your computer and use it in GitHub Desktop.
Handle your create and update code in one method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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