Ch8 из книги Beginning 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 %>");
Может ли какой-нибудь добрый человек объяснить, почему это не работает, спасибо