# Observe\_form, rjs for form validate and a lot of mistakes!

**URL:** <https://www.ruby-forum.com/t/observe-form-rjs-for-form-validate-and-a-lot-of-mistakes/142763>\
**Category:** Rails\
**Created:** [July 11, 2008, 5:33am UTC](https://www.ruby-forum.com/t/observe-form-rjs-for-form-validate-and-a-lot-of-mistakes/142763 "2008-07-11T05:33:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [July 11, 2008, 5:33am UTC](https://www.ruby-forum.com/t/observe-form-rjs-for-form-validate-and-a-lot-of-mistakes/142763/1 "2008-07-11T05:33:46Z")

</div>

First, thanks for reading this post!

Today i’m trying to implement a real-time form validator.

I have a model (user) within:

```
   t.column :email, :string
   t.column :name, :string
   t.column :surname, :string
   t.column :nickname, :string
   t.column :gender, :integer
   t.column :site, :string
   t.column :birthday, :datetime
   t.column :culinary, :string
   t.column :avatar, :string
   t.column :description, :string
   t.column :password, :string
   t.column :active, :boolean, :default => false

```

the validation rules:

validates\_uniqueness\_of :email, :nickname  
validates\_length\_of :password, :within =\> 4…10  
validates\_length\_of :email, :maximum =\> 50  
validates\_presence\_of :name, :surname, :email, :password, :nickname  
validates\_format\_of :email,  
:with =\>  
/^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i # ( needs a improve )

and the controller code:

def signup  
@title = “site\_name: signup”  
unless logged\_in?  
@user = User.new(params[:user])  
if @user.valid? #@user.save  
flash[:notice] = “user registered”  
end  
else  
redirect\_to :controller =\> “site\_name”, :action =\> “index”  
end  
end

And i wan’t to use XML (RJS), to validate in real-time what the user  
type in  
fields. If what was type can’t be allowed (see validate rules) a message  
or  
a red border indicates a error. I try several times, read a lot of  
articles  
in google and see 4 railscasts.

Can anyone help me?

Obs.: sorry for my poor english.

–  
Regards,

Luiz Vitor Martinez C.  
cel.: (11) 8187-8662  
blog: [rubz.org](http://rubz.org)  
engineer student at maua.br

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [July 11, 2008, 11:19am UTC](https://www.ruby-forum.com/t/observe-form-rjs-for-form-validate-and-a-lot-of-mistakes/142763/2 "2008-07-11T11:19:40Z")

</div>

On 11 Jul 2008, at 04:33, Luiz Vitor Martinez C. wrote:

> ```
> end
> 
> ```

I have a vague feeling there’s already something like this. First off,  
xml and rjs have nothing to do with each other.  
In a nutshell if you use observe\_form, an ajax request will submit the  
form whenever the fields change. In you controller you can cal  
User.new on those submitted parameter. In your rjs you can render the  
error messages (using error\_messages\_for or rolling your own) and  
insert them into a div (page.insert\_html etc…)

Fred
