How do I validate the presence of one field or another but not both and at least one ?
标签:
ruby-on-rails
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
- Rails how to handle error and exceptions in model
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
Example for rails 3.
#Father last name or Mother last name is compulsory
Try above simple example.
Your code will work if you add conditionals to the numericality validations like so:
I put my answer to this question below. In this example
:description
and:keywords
are fields which one of this not be blank:You can even do this with 3 or more values:
I think this is more idiomatic in Rails 3+:
e.g: For validating that one of
user_name
oremail
is present: