# Modal validation not works

**URL:** <https://www.ruby-forum.com/t/modal-validation-not-works/170737>\
**Category:** Rails\
**Created:** [June 22, 2009, 9:37am UTC](https://www.ruby-forum.com/t/modal-validation-not-works/170737 "2009-06-22T09:37:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 22, 2009, 9:37am UTC](https://www.ruby-forum.com/t/modal-validation-not-works/170737/1 "2009-06-22T09:37:29Z")

</div>

Hi everyone,  
i have 20 fields in users table.  
in my admin profile module the admin can modify his infomation.  
but only 12 fields he can able to modify.  
so in my controller

if params[:profileinfo][:first\_name]

```
@profileinfo.update_attribute(:first_name,params[ :profileinfo

```

][:first\_name])

end

the above simply saves what i enter into the field.why it doesnot  
consider the modelvalidation.  
any guess.  
Thanks

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 22, 2009, 10:51am UTC](https://www.ruby-forum.com/t/modal-validation-not-works/170737/2 "2009-06-22T10:51:25Z")

</div>

On Jun 22, 8:37 am, Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> the above simply saves what i enter into the field.why it doesnot  
> consider the modelvalidation.  
> any guess.

Because update\_attribute ignores validations completely. The intent is  
that it is useful when just changing an attribute (eg flipping a flag)  
where you don’t really care about the overall validity of the object.

Fred

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 22, 2009, 10:56am UTC](https://www.ruby-forum.com/t/modal-validation-not-works/170737/3 "2009-06-22T10:56:08Z")

</div>

On Jun 22, 8:37 am, Newb N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> the above simply saves what i enter into the field.why it doesnot  
> consider the modelvalidation.

Please check the API docs ([http://api.rubyonrails.org/](http://api.rubyonrails.org/)) first for  
things like this.

update\_attribute: Updates a single attribute and saves the record  
without going through the normal validation procedure.

I expect if you’re calling update\_attribute 12 times you’re doing  
something wrong; either call update\_attributes with a hash, or set  
each attribute individually:

@profileinfo.first\_name = params[:profileinfo][:first\_name]  
@profileinfo.last\_name = params[:profileinfo][:last\_name]  
@profileinfo.save

Even better, look into the use of attr\_protected and attr\_accessible  
and just use a mass assignment:

@profileinfo.update\_attributes(params[:profileinfo])

-Matt

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 22, 2009, 11:14am UTC](https://www.ruby-forum.com/t/modal-validation-not-works/170737/4 "2009-06-22T11:14:18Z")

</div>

Hi…  
thanks for the reply…  
i have below validation in my model…  
validates\_exclusion\_of :login,  
:in =\> %w( admin ),  
:message =\> “Name admin is not allowed”

it validates tat the admin should not be used as login name…  
in my admin profile module the admin can modify his infomation.  
when i save the instance of admin it gives me the above validation error  
…  
is it possible to skip the exclusion of validation when i update the  
admin record…

pls suggest me…  
thanks

---

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [June 22, 2009, 11:36am UTC](https://www.ruby-forum.com/t/modal-validation-not-works/170737/5 "2009-06-22T11:36:42Z")

</div>

On 22 Jun 2009, at 10:14, Newb N. wrote:

> when i save the instance of admin it gives me the above validation  
> error  
> …  
> is it possible to skip the exclusion of validation when i update the  
> admin record…

Just don’t use update\_attribute. Use save, update\_attributes etc.

Fred
