Try this

:unless => Proc.new {|user| user.password.nil?}

Essentially it will check if you are sending a password attribute to the
user or not while updating the user record and will check for this
validation only if password attribute is present.




Chirag
http://sumeruonrails.com



On Thu, Aug 18, 2011 at 11:05 PM, Leonel *.* <li...@ruby-forum.com> wrote:

> Can someone help me complete this piece of code?
>
> I'm thinking about using :unless because the only place where I wouldn't
> like the password validation is in the Edit User page.
>
> validates :password,
> :presence => true,
> :length => { :minimum => 6, :maximum => 20, :message => 'should have
> between 6 to 12 characters' },
> :confirmation => true,
> :unless => ????????????
>
> I tried...
> :unless => params[:controller] == 'users' and params[:action] == 'edit'
>
> but I got the following error...
> Routing Error
> undefined local variable or method `params' for #<Class:0x7f92ca83a518>
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to