1
A
回答
1
下面是型號代碼:
class Person
belongs_to :city
end
class City
has_many :persons
validate_on_create :check_populations
def check_populations
return if persons.length > 10
end
end
0
您可以在模型中使用自定義驗證程序。有一個看起來在這裏:https://stackoverflow.com/a/2263294/1321564
相關問題
- 1. Rails - 費率限制模型的創建
- 2. MVC模型綁定限制
- 3. 限制從改變模型
- 4. 增加限制模型
- 5. Rails模型和控制器
- 6. Rails權限:對不同模型的不同類型的權限
- 7. Rails 3的模型聯接限制到一個結果
- 8. 如何在rails中限制模型的嵌套屬性數
- 9. 限制訪問Rails中的一些模型項3
- 10. 的Rails 3.1的限制兒童模特
- 11. 限制整型模板參數
- 12. 限制模型級別的Django訪問
- 13. 通過計數限制ForeignKey模型
- 14. 在django模型中限制圖片
- 15. Django的限制的模型中
- 16. Django管理限制模型外鍵
- 17. Cakephp 3 - 限制()和包含的模型
- 18. Django模型限制ManyToManyField所有者
- 19. 模型軌道中的限制字數
- 20. 在JSP中限制模型的範圍
- 21. 如何限制基於相關模型
- 22. 模型的記錄數量限制
- 23. django模型字段限制選擇從其他模型領域
- 24. 權限模型
- 25. Rails控制器無法識別模型
- 26. Rails中的模型版本控制
- 27. Rails模型/控制器結構
- 28. Rails:在模型上強制訂購
- 29. Ruby On Rails模型/控制器問題
- 30. Rails一個模型 - 許多控制器
好像http://stackoverflow.com/questions/1611887/calling-custom-validation-methods-in-rails的副本可以執行自定義驗證。 – kobaltz 2013-02-23 17:55:35