我的 rails 控制台两次显示相同的模型 - 未初始化常量错误
My rails console shows the same model twice - uninitialized constant error
我有一个名为 pictures.rb
又名图片 class 的模型,它应该映射到图片 table 但在 rails 控制台中它显示了两次?
irb(main):013:0> @models = ActiveRecord::Base.subclasses.collect { |type| type.name }.sort
=> ["Picture", "Picture"]
我正在尝试在我的 ControlPanelController 索引函数中使用 Picture class aka picture.rb 模型
所以当我加载我的索引页面时,我收到以下错误
uninitialized constant ControlPanelController::Picture
def index
@pictures = Picture.all
end
我猜可能是因为 Picture 模型在 rails 控制台中出现了两次?不确定。
它找不到它的原因是您的模型文件名为 pictures.rb。
文件名应为 picture.rb(不是复数)。
应该是:
app/models/picture.rb:
class Picture< ActiveRecord::Base
...
end
我有一个名为 pictures.rb
又名图片 class 的模型,它应该映射到图片 table 但在 rails 控制台中它显示了两次?
irb(main):013:0> @models = ActiveRecord::Base.subclasses.collect { |type| type.name }.sort
=> ["Picture", "Picture"]
我正在尝试在我的 ControlPanelController 索引函数中使用 Picture class aka picture.rb 模型
所以当我加载我的索引页面时,我收到以下错误
uninitialized constant ControlPanelController::Picture
def index
@pictures = Picture.all
end
我猜可能是因为 Picture 模型在 rails 控制台中出现了两次?不确定。
它找不到它的原因是您的模型文件名为 pictures.rb。
文件名应为 picture.rb(不是复数)。
应该是:
app/models/picture.rb:
class Picture< ActiveRecord::Base
...
end