我有两个型号User和Leave class User ActiveRecord::Base has_many :leaves ...endclass Leave ActiveRecord::Base belongs_to :user #attr_accessible :user_id #default_scope - { order('created_at DESC') } validates :user_id, presence: true e
class User < ActiveRecord::Base has_many :leaves ... end class Leave < ActiveRecord::Base belongs_to :user #attr_accessible :user_id #default_scope -> { order('created_at DESC') } validates :user_id, presence: true end
哪些是基本模型用户有许多叶子和叶子属于用户.但是,当我这样做
@leaves = @user.leaves
在users_controller中我得到了这个奇怪的错误“未初始化的常量User :: Leafe”,但我无法找到拼写错误的“离开”.检查了所有迁移和shema.rb.在此代码之前,我正在调用@ leaves2 = Leave.all并且正在传递OK,但是当我执行“@ user.leaves”时,它在具有NameError的控制台上打破了“500 Internal Server Error”.是否可以执行错误捕获或类似的操作来查看此错误的确切位置.
同样在rails控制台中无法获取@ leaves = @ user.leaves,它以“NameError:uninitialized constant User :: Leafe”退出
活动记录看到叶子的奇异形式.您可以使用变形覆盖它配置/初始化/是inflections.rb
ActiveSupport::Inflector.inflections do |inflect| inflect.irregular 'leave', 'leaves' end