I have a form successfully submitting data via ajax, but I can’t figure out how to trigger an event after the ajax action. I’d like to reload the partial containing the form after a new record is submitted.
View
#container
#partial
<%= form_for [@qa, @newpdd], :remote => true do |f| %>
....
<%= f.submit "add %>
PDD Controller
def create
@pdd = Pdd.create!(params[:pdd])
@pdd.qa_id = params[:qa_id]
@qa = Qa.find(params[:qa_id])
respond_to do |format|
if @pdd.save
format.html { redirect_to(@qa, :notice => 'Pdd was successfully created.') }
format.xml { render :xml => @pdd, :status => :created, :location => @pdd }
format.js
# render :partial => pddsection
else
format.html { render :action => "new" }
format.xml { render :xml => @pdd.errors, :status => :unprocessable_entity }
end
end
end
create.js.erb
$('#partial').replaceWith("<%= escape_javascript(render :partial => 'pdds/partial') %>");
Any ideas?
I ended up abandoning the :remote => true condition in the form as demonstrated in this rails cast:
Railscast 136
Everything now works as expected. Thanks for the help.