Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的模型中有这个:
validates :polarity, presence: true
我只想允许1和-1(因为它是一个投票系统)。
1
-1
如何做到这一点?
正如评论中所建议的:
validates :polarity, presence: true, inclusion: { in: [-1, 1] }