Rails' validate method and ajax #31

Open
mrrooijen opened this Issue Dec 16, 2009 · 1 comment

Projects

None yet

2 participants

@mrrooijen

Hi.

I was wondering, as it wasn't clear to me, whether validatious-on-rails supports the built-in custom Rails "validate" method? I know that the validates_uniqueness_of method does an ajax call, but is there a way to create a custom validate method that gets checked through ajax?

Example:

class User < ActiveRecord::Base
  validate :invitation, :client_side => false
  def invitation
    unless self.find_by_email_and_invitation(email, invitation_code)
      # if the specified email and invitation code do not match, add an error to the field
      errors.add(:invitation, "This invitation is invalid.")
    end
  end
end

Basically something like that, where you just call the "validate" method to create a new custom validation that (I would assume) will always be called through an ajax call..

Is this already possible? Will it be possible in later versions?

I believe I did read something about "Custom Validations" but I wasn't sure what you meant by that in the README so I wanted to verify that I'm not missing anything here.

Anyway, I love this tool regardless, and plan to use it in all future projects. With just the built-in Rails validations support this already is an amazingly awesome tool to use!

Thanks!
Michael

@grimen
Owner
grimen commented Dec 16, 2009

Hi, good to know that you like it. Yes, it will be possible to make custom validations validatable thorugh AJAX, actually it works now already if you extend ActiveRecord::Base with a validates_XXX method of choice. The AJAX-stuff s not stable though, as you may already know - had little time to fix it yet. I did quite some work on refactor the internals to be more pluggable as an API (for custom remote/client validators), and you can peep a preview of this stuff here: http://github.com/grimen/validatious-on-rails/tree/refactor_model_validations It still got a failin test on the AJAX controller, so don't expect it to work yet - but might give a hint if you interested.

cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment