Skip to content

Instantly share code, notes, and snippets.

@nuwansh
Last active October 2, 2015 05:58
Show Gist options
  • Save nuwansh/2185033 to your computer and use it in GitHub Desktop.
Save nuwansh/2185033 to your computer and use it in GitHub Desktop.
Create Method
@object = object.new(params[:object])
respond_with(@object) do |format|
if @object.save
format.html {
flash[:notice] = "Created a new object successfully."
redirect_to objects_path
}
format.json { render :json => object.find(@object).to_json, :status => :created, :location => @object }
else
format.html { render :new }
format.json { render :json => @object.errors.to_json, :status => :unprocessable_entity }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment