I have model Post with boolean field default. Post belongs to User. I want to ensure that there is only one default (e.g. set to true) post for user. Tried this:
validates :default, uniqueness: { scope: :user_id }, if: :default?
but it allows to create two Posts with default: true, user_id: 1
Can you please help me?
P.S. this construction works perfectly for validates :name, uniqueness: { scope: :user_id }, unless: :default? may be there is something wrong with booleans?
Problem solved. After 10
rails srestarts it just started to work.