Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation 如何确保在rails中使用正确的帐户保存模型?_Validation_Ruby On Rails 3 - Fatal编程技术网

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