trnc
trnc

Reputation: 21577

Rails3 Ajax form (jquery) and model validation

i send an form remotely and wanted to add a validation to it. this is in my model:

  validates :email, :presence => true, :email => true

validation works fine, when email is valid it adds it to the database, if not, then not. my problem is, whenever i submit the form, it renders my subscribe.js file:

$('.form').html("<p><strong>Thank you for your interest!<br />We'll keep you up-to-date.</strong></p>"); 

how can i tell rails, that if the email adress is unvalid, it should render another .js file? or is there another way?

thank you!

Upvotes: 0

Views: 841

Answers (1)

Samo
Samo

Reputation: 8240

Maybe something like this...

if @object.save 
  respond_to do |format|
    format.js
  end
else   
  render # something else
end

Upvotes: 1

Related Questions