Skip to content

Instantly share code, notes, and snippets.

@adriand adriand/gist:3177806
Created Jul 25, 2012

Embed
What would you like to do?
unobtrusive AJAX
# in the view
= form_for([:forge, @job, job_application], :remote => true) do |f|
# in the JS header portion of the view
$("form").on("ajax:success", function(data, status, xhr) {
alert("Success");
});
# in the controller, just make sure you handle format.js, and use render :nothing => true, NOT render :text => "Success"
def update
@job_application.resume = nil if params[:remove_asset] == "1"
if @job_application.update_attributes(params[:job_application])
respond_to do |format|
format.html do
flash[:notice] = 'Job application was successfully updated.'
redirect_to(forge_job_job_applications_path(@job_application.job_id))
end
format.js { render :nothing => true } # caution: render :text => "Success" will not trigger ajax:success
end
else
respond_to do |format|
format.html { render :action => "edit" }
format.js { render :text => "Failure", :status => 500 }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.