AJAX calls don't do validation

Chatting on the IRC channel today to people (thanks!) it came up that
submitting a form remote bypasses the :validates… in the model. At
least thats how it looks from my tests and what people said is the
current behaviour.

Is this the case?

If so, is there a way around it or will it change in the future? I can
imagine good reasons for the current behaviour.

have fun,

SteveC [email protected] http://www.asklater.com/steve/

Chatting on the IRC channel today to people (thanks!) it came up that
submitting a form remote bypasses the :validates… in the model. At
least thats how it looks from my tests and what people said is the
current behaviour.

Is this the case?

I don’t believe this to be the case. The form_remote routine is
invoking a controller method which by default isn’t going to know or
care how it’s called.

When the controller manipulates models it calls the Ruby methods defined
in the model classes. From the model’s point of view a call from a
controller called by form_remote looks identical to a call from a
controller not called by form_remote, which looks identical to a call
not coming from a controller at all (e.g., by Ruby code not using
anything other than the AR part of Rails, or even code called from
script/console). If model methods are called which trigger validation
in normal circumstances, they should trigger validation in the
circumstances you describe.

It seems to me it would be cumbersome to implement the “don’t call
validators when using form_remote” semantics even if that’s what one
wanted, and I can’t imagine that’s what the Rails developers have
wanted.

That being all theoretical, in practice we’re using AJAX heavily,
including lots of form_remote calls, and relying on the validators
in the models quite heavily. They do indeed get called, at least in our
experience.

Perhaps you mean something else?

Rick

http://www.rickbradley.com MUPRN: 307
| website as in
random email haiku | a regular (but high
| quality) e-shop.

SteveC wrote:

Chatting on the IRC channel today to people (thanks!) it came up that
submitting a form remote bypasses the :validates… in the model. At
least thats how it looks from my tests and what people said is the
current behaviour.

Is this the case?

If so, is there a way around it or will it change in the future? I can
imagine good reasons for the current behaviour.

have fun,

SteveC [email protected] http://www.asklater.com/steve/

Not sure if I understand you correctly, but I wrote some code to get
validations with AJAX:
http://wiki.rubyonrails.org/rails/pages/HowToValidateWithAjaxInPlaceEditor

I’m pretty sure e.g. link_to_remote does not bypass validations, but
since the errors occur within the javascript-triggered connection, you
only get to see the errors if you pass them back somehow (as exemplified
on the page I linked above).