Suppose you have an edit form with :remote => true
. Your controller method looks like
def update
@article = Article.find(params[:id])
respond_to do |format|
if @article.update_attributes(params[:article])
format.html { redirect_to @article}
format.js { render :js => "window.location.replace('#{article_path(@article)}');"}
else
format.html { render :action => "edit" }
# Render update.js.erb which replaces the body of the form
format.js {}
end
end
end
What's the best way to do the redirect on successful article update in Rails 3.2.1? The raw JS solution seems a little sleazy, but I do like the fact that it's obvious that it's performing the same function as the format.html
version.
I would prefer a solution that does not use RJS (if that even works in Rails 3.2?)