Reputation: 12379
I would like to only allow certain validations within production
vs other environments for an app.
For example, I have tried to add:
if Rails.env.production?
validates :email, :uniqueness => true
validates :phone, :uniqueness => true
end
However this will not work. How can one add validations only to specific environment modes?
Upvotes: 2
Views: 1842
Reputation: 7733
Try this -
validates :email, :uniqueness => true, :if => lambda{ Rails.env.production?}
validates :phone, :uniqueness => true, :if => lambda{ Rails.env.production?}
Upvotes: 7
Reputation: 204
Totally agree with the comments, but if you really want to do this, try the :if option
validates_uniqueness_of :email, :if => Rails.env.production?
Upvotes: 2