我面临以下错误:
NameError at
uninitialized constant XController::Sheep
在这条线上
server = Sheep.find_by_id(id)
这是我的设置:
在下面models/sheep.rb
class Sheep < ActiveRecord::Base
has_many :kids
end
在下面models/kid.rb
class Kid < ActiveRecord::Base
belongs_to :sheep # I tried adding , :class_name => 'Sheep' didn't do anything
end
在下面config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.uncountable 'sheep'
end
表名其实是sheep
我查的
我还应该检查什么?
编辑:在控制器中controllers/farm.rb
我打了两个电话:
@kid = Kid.find_by_id params[:id]
@sheep = Sheep.find_by_id(id) # works only when adding :: as in the answer