Reputation: 1042
I am new in Ruby and Ruby on Rails, so maybe my question is not appropriate. I am making a Tic Tac Toe game and when I try to validate my player names like this:
validates_presence_of :player_1, :player_2
validates_uniqueness_of :player_1
validates_uniqueness_of :player_2
And do this in my config/initializers/cleaner.rb
Game.destroy_all
my validation does not work. I also tried Ruby on Rails validation by pair of properties, but it does not work. Thanks in advance.
Upvotes: 0
Views: 62
Reputation: 1601
Please try this:
validates : player_1, :presence => true, :uniqueness => { :scope => : player_2 }
validates : player_2, :presence => true, :uniqueness => { :scope => : player_1 }
OR
validates :player_1, uniqueness: { scope: :player_2 }
validates :player_2, uniqueness: { scope: :player_1 }
Upvotes: 1