[英]NameError: uninitialized constant Api::V1::Item::ItemsController::Item
I have controller 我有控制器
class Api::V1::Item::ItemsController < ApplicationController
def index
@items = Item.all
render json: @items
end
end
and routes for this controller 和该控制器的路线
namespace :api do
namespace :v1 do
namespace :item do
resources :items
end
end
end
If i check this in postman, i obtain an error: 如果我在邮递员中检查此内容,则会收到错误消息:
{
"status": 500,
"error": "Internal Server Error",
"exception": "#<NameError: uninitialized constant Api::V1::Item::ItemsController::Item>",
}
But if i modify controller`s method index like 但是如果我修改控制器的方法索引
def index
render json: { check: 'Nice' }
end
everything will be fine. 一切都会好起来的。 Pls explain me what the problem is 请向我解释问题是什么
Try using absolute constant path ::Item
instead of relative constant path Item
. 尝试使用绝对恒定路径::Item
而不是相对恒定路径Item
。
def index
@items = ::Item.all
# ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.