【发布时间】:2012-03-19 08:54:37
【问题描述】:
假设您有一个带有:remote => true 的编辑表单。你的控制器方法看起来像
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?)
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2