我试图绕过这个奇怪的错误一段时间了。这是我的基本控制器:
get :index, provides: :json do
@requests = Request.order(:created_at)
render 'requests/index'
end
get :show, with: :id, provides: :json do
@request = Request.find_by(id: params[:id])
render 'requests/show'
end
这是我的rabl json文件在每种情况下的样子:
index.json.rabl:
collection @requests
attributes :created_at, :updated_at, :user_id, :request_type
show.json.rabl:
object @request
attributes :id
第一个路由(即:index)很好地返回Request对象数组,但第二个路由(即:show)抛出以下错误:
NoMethodError at /show/1
undefined method `head?' for #<Request:0x007f6814485840>
谁能指出这个错误可能是关于什么?它为什么要找头?函数?
不要使用@request实例变量。机架栈使用它来存储HTTP请求。