Hi I have in my user model attr_accessor :no_password_validation_needed with_options :unless => :no_password_validation_needed do |p| p.validates_length_of :password, :minimum => 6 p.validates_confirmation_of :password end And from controller I do @user.no_password_validation_needed = false @user.update_attributes(params[:user]) And it works perfectly and now validation happens. If it is @user.no_password_validation_needed = true Then also I get the expected result as now validation not happens But now when @user.no_password_validation_needed = 2 #or any other value Now I get unexpected result as validation not happens That is same result when true? Why this?What modification should I make?Please help Thanks in advance Tom -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 24, 6:09 am, Tom Mac <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > But now when > @user.no_password_validation_needed = 2 #or any other value > > Now I get unexpected result as validation not happens That is > same result when true? Why this?What modification should I make?Please > helpThat''s how truth values work in ruby - anything other than nil or false is generally considered true. Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Does this help?>> irb >> puts "show" if trueshow>> puts "show" if false=> nil>> puts "show" if nil=> nil>> puts "show" if 2show>> puts "show" if DateTime.newshow In ruby it''ll be true unless it receives nil or false. Kind Regards Luke -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 March 2010 08:07, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That''s how truth values work in ruby - anything other than nil or > false is generally considered true.Have a look at the Ruby Facets library for their "kernel.true?" method: http://facets.rubyforge.org/apidoc/api/core/classes/Kernel.html#M000436 It only returns true for a TrueClass object. If you don''t want to install the whole library, you can write a monkey patch of your own to add this functionality. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.