作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有嵌套属性的表单。现在在我的 :reject_if =>
声明我想检查嵌套模型上的属性,比如 first_record?
有没有办法访问这样的方法?在我看来,您只能访问提交的属性哈希,例如检查字段是否为空。谢谢!
最佳答案
根据文档 http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
或者, :reject_if 也接受使用方法的符号:
class Member < ActiveRecord::Base
has_many :posts
accepts_nested_attributes_for :posts, :reject_if => :new_record?
end
class Member < ActiveRecord::Base
has_many :posts
accepts_nested_attributes_for :posts, :reject_if => :reject_posts
def reject_posts(attributed)
attributed['title'].blank?
end
end
关于ruby-on-rails - rails 接受_nested_attributes 和 :reject_if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13683948/
我是一名优秀的程序员,十分优秀!