In Rails 3.2 I have this syntax:
validates_uniqueness_of :sport_name, :scope => :sports_org_id
This is now deprecated in rails 4 but i can't figure out the new syntax. I want to validate both presence and uniqueness for a data field.
how about this ?
validates :sport_name, uniqueness: {scope: :sports_org_id}, presence: true
See The Rails Guides for more info. Your syntax dates from rails 2 !
EDIT
You can now also use the allow_blank
option instead of a presence validation, which makes for nicer error messages :
validates :sport_name, uniqueness: {scope: :sports_org_id, allow_blank: false}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With