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 -- Posted via http://www.ruby-forum.com/.
On Jun 22, 8:37 am, Newb Newb <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Newb <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 -- Posted via http://www.ruby-forum.com/.
On 22 Jun 2009, at 10:14, Newb Newb wrote:> > 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.... >Just don''t use update_attribute. Use save, update_attributes etc. Fred> pls suggest me.. > thanks > -- > Posted via http://www.ruby-forum.com/. > > >
Seemingly Similar Threads
- Queries Regarding Usage of PGOInstrumentation Passes instead of Deprecated ProfileInfo
- [LLVMdev] Profiling in LLVM Patch Followup 1
- [LLVMdev] Loading ProfileInfo in Backend. (Was: [PATCH] & Question: Preserving ProfileInfo for backend.)
- [LLVMdev] Loading ProfileInfo in Backend. (Was: [PATCH] & Question: Preserving ProfileInfo for backend.)
- [LLVMdev] FunctionPass Analysis is not saved after ModulePasses run?