Ruby on rails 未初始化的常量UsersController::Children

Ruby on rails 未初始化的常量UsersController::Children,ruby-on-rails,Ruby On Rails,我有4个模型:项目、子项目、子项目、用户: class User < ActiveRecord::Base has_many :projects end class Subproject < ActiveRecord::Base belongs_to :project has_many :children, :dependent => :destroy accepts_nested_attribut

我有4个模型:项目、子项目、子项目、用户:

    class User < ActiveRecord::Base
     has_many :projects    
    end

    class Subproject < ActiveRecord::Base
      belongs_to :project
      has_many :children, :dependent => :destroy
      accepts_nested_attributes_for :children, :allow_destroy => true
    end

    class Project < ActiveRecord::Base
     belongs_to :user
     has_many :subprojects,  dependent: :destroy
    end

    class Child < ActiveRecord::Base

    end
我想向所有用户发送电子邮件。但是,为什么我不能设置@children=children.all

我使用的是Rails 4.02


谢谢

您需要使用
儿童
而不是下一行中的
儿童

@children = Children.all #wrong

@children = Child.all #correct

因为您需要使用模型类名(即
子类
而不是
子类
)来查询
ActiveRecord

请更具体一点-问题是什么?@fafafa我已更新我的答案:)@fafafa请勾选接受我的答案:
@children = Children.all #wrong

@children = Child.all #correct