【发布时间】:2011-07-07 17:14:31
【问题描述】:
我的 rails 应用程序中有一个简单的视频模型,has_many cmets。我在视频的显示页面上显示这些 cmets。当我提交表格时,一切正常;但是,如果 Comment 模型上存在验证错误,那么我的系统就会崩溃。如果评论模型上存在验证错误,我只想再次呈现视频的显示页面,并显示验证错误样式。如何在我的创建操作中执行此操作?非常感谢!
class CommentsController < ApplicationController
def create
@video = Video.find(params[:video_id])
@comment = @video.comments.build(params[:comment])
if @comment.save
redirect_to @video, :notice => 'Thanks for posting your comments.'
else
render # what? What do I render in order to show the video page's show action with the validation error styling showing? Please help!
end
end
end
【问题讨论】:
标签: ruby-on-rails controller render