Modal validation not works

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

On Jun 22, 8:37 am, Newb N. [email protected]
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

On Jun 22, 8:37 am, Newb N. [email protected]
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/) 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

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

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