Skip to content

Instantly share code, notes, and snippets.

@amster
Created April 5, 2011 06:28
Show Gist options
  • Save amster/903123 to your computer and use it in GitHub Desktop.
Save amster/903123 to your computer and use it in GitHub Desktop.
def create
@my_model = MyModel.new(params[:my_model])
respond_to do |format|
if @my_model.save
format.html { redirect_to(my_models_path, :notice => 'Success') }
format.js { render :json => { :success => true, :message => "Success"}, :content_type => 'text/json' }
format.xml { render :xml => @my_model, :status => :created, :location => @my_model }
else
format.html { render :action => "new" }
format.js { render :json => { :success => false, :message => "Fail"}, :content_type => 'text/json' }
format.xml { render :xml => @my_model.errors, :status => :created, :location => @my_model }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment