【发布时间】:2011-05-08 03:34:20
【问题描述】:
Beginning Rails 书的第 8 章有一个 Ajax 表单示例,它可以正常工作,只是它不会针对无效输入输出警报。
控制器代码为:
def create
@comment = @article.comments.new(params[:comment])
if @comment.save
respond_to do |format|
format.html { redirect_to @article, :notice => 'Thanks for your comment' }
format.js
end
else
respond_to do |format|
format.html { redirect_to @article, :alert => 'Unable to add comment due to errors in your input'}
# logger.info("#{Time.now} Ajax invalid validation
##{@comment.errors.full_messages}!")
format.js { render 'fail.js.erb' }
end
end
end
“fail_create.js.erb”文件包含一行;
alert("<%= @comment.errors.full_messages.to_sentence %>");
哪位好心人能解释一下为什么这不起作用,谢谢
【问题讨论】:
标签: ajax ruby-on-rails-3