假设您有一个编辑表单,其编号为:remote => true
。您的控制器方法看起来像如何在成功提交AJAX表单后重定向(Rails 3.2)
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
什么是在Rails 3.2.1中成功更新文章的重定向的最佳方式?原始的JS解决方案看起来有些低俗,但我确实喜欢这样一个事实,即很明显它执行的功能与format.html
版本相同。
我宁愿不使用RJS(if that even works in Rails 3.2?)