【发布时间】:2011-06-29 05:58:42
【问题描述】:
我在文章/显示页面中有一个 cmets 表格。在此页面中,它显示文章并具有 cmets 表单。
当我提交有验证错误的评论时,我需要它返回文章/显示页面,并在那里显示错误。
我应该将render :action => 'new' 更改为其他内容吗?
在 Comment 控制器中,我尝试了:
def create
...
if @comment.save?
redirect_to article_path(@comment.article), :notice => "Posted comment!"
else
# render :action => 'new'
render 'articles/show"
end
end
但这会报错,因为应用不知道根据 ID 显示哪篇文章。
编辑:我找到了this 解决方案。方法是使用会话来传递错误。这是正确的方法吗?
【问题讨论】:
标签: ruby-on-rails-3 validation forms