ylluminate
ylluminate

Reputation: 12379

Certain validations only in Rails.env.production?

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

Answers (2)

Sandip Ransing
Sandip Ransing

Reputation: 7733

Try this -

validates :email, :uniqueness => true, :if => lambda{ Rails.env.production?}
validates :phone, :uniqueness => true, :if => lambda{ Rails.env.production?}

Upvotes: 7

THEM
THEM

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

Related Questions