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.
有一个收入模型属于房地产和收入模型有一个列年份,在将新收入保存到收入模型之前,我想检查收入的当前值是否已经存在于 @estate.revenue.Year 的模型中,如果没有,则应保存它,否则会引发错误。
也许您可以在收益模型中使用唯一性验证器:
validates :year, uniqueness: { scope: estate_id }
或者,使用旧版本的 Rails/Ruby:
validates :year, :uniqueness => { :scope => estate_id }