0

How do you show the following errors that fail Rails validation using AJAX?

enter image description here

I have the following code in controller

      flash[:notice] = 'Please correct the errors below and try again.'
            format.html { render :action => :new }
            format.js 
      end

Added to view

 :remote => true 

And then in create.js.erb I check the flash, but how do I show Rails errors that are shown when not using AJAX? or do I have to write validations from scratch here?

 <% if flash.present? %>

 <% end %>
1

1 Answer 1

1

You might want to check model_name.errors?

otherwise you can create a empty div. Fill that div from ajax with the proper message regarding the error.

In create.js.erb

('#error').html("error")

In View

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.