Validation 如何确保在rails中使用正确的帐户保存模型?
如果我设置了以下型号:Validation 如何确保在rails中使用正确的帐户保存模型?,validation,ruby-on-rails-3,Validation,Ruby On Rails 3,如果我设置了以下型号: class Member < ActiveRecord::Base has_many :children end class Child < ActiveRecord::Base belongs_to :member has_many :photos end class Photo < ActiveRecord::Base belongs_to :child end 类成员
class Member < ActiveRecord::Base
has_many :children
end
class Child < ActiveRecord::Base
belongs_to :member
has_many :photos
end
class Photo < ActiveRecord::Base
belongs_to :child
end
类成员
创建新照片时,确保其与会员帐户中的孩子关联的最佳方式是什么
我的登录工作正常,并且有一个当前的_memberhelper方法,在模型中似乎不可用因此,据我所知,“Rails方式”™" 这样做的目的是将条件放入控制器中 例:
unless current_member.children.collect { |child| child.id.to_s }.include?(@photo.child_id)
@photo.errors.add :child_id "this is not your child"
end