| View previous topic :: View next topic |
| Author |
Message |
Swadin
Joined: 23 Jun 2008 Posts: 2
|
Posted: Mon Jun 23, 2008 12:46 pm Post subject: How to apply the conditional validations in the rails code.? |
|
|
Hi friends,
I want to apply the validations must be done based on the condition.Is there any way to apply the conditional validations in the rails.?
Thanks to all inadvance. |
|
| Back to top |
|
 |
s.nagesh
Joined: 23 Jul 2007 Posts: 131
|
Posted: Tue Jun 24, 2008 3:22 am Post subject: |
|
|
By default, validations will take place every time the model is saved. Sometimes you only want a validation to happen when certain conditions are met.
in your model:
validates_presence_of :country
validates_presence_of :state, :if => :in_india?
def in_india?
country == 'india'
end |
|
| Back to top |
|
 |
|