Forum: Ruby on Rails if condition on validates_presence_of is not working

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Neeraj K. (Guest)
on 2006-01-14 23:34
(Received via mailing list)
class Event < ActiveRecord::Base
  attr_accessor :step_processing

  validates_presence_of :name,:description , :if =>  (:step_processing
==
4)
end

class TestController < ApplicationController

def bar
  @event = Event.new
  @event.step_processing = 4
  @event.name = 'foo'
  @event.save
end

end

In the above code :step_processing a non-database field. It's just there
to
control the processing. The validation should take place only when the
step_processing is '4' but in reality it's done every single time. I
guess I
am goofing up the syntax or something like that.

Thanks.
This topic is locked and can not be replied to.