Beginning Rails book的第8章有一个Ajax表单示例,它工作正常,除非它不输出无效输入的警报。警报不适用于Rails/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 %>");
一些善良的人可以解释为什么这是行不通的,谢谢
一个错字只,警报仍然不能正常工作。在Rails 3中包含Ajax功能的最佳方式是什么? – Alan 2011-05-08 08:41:58