Warning doesn't work in Rails / ajax situation?

There is an example of an Ajax form in the Ch8 Beginning Rails book that works fine, except that it doesn't display a warning about invalid input.

Controller Code:

    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

The file 'fail_create.js.erb' contains one line;

alert("<%= @comment.errors.full_messages.to_sentence %>");

Can some person explain why this is not working, thanks

+3
source share
2 answers

You show "fail.js.erb", but in your question you say that the file "fail_create.js.erb" contains the code. Is this a typo in your question or a problem in the code?

, RJS Rails. , , , Rails. Javascript ( ).

0

jQuery 1.4.2

1.4.4,

0

All Articles