Search code examples
jsonpadrinorabl

undefined method `head?' using rabl


I am trying to get around this weird error for some time now. This is the basic controller I have:

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

This is how my rabl json files look like in each case:

index.json.rabl:

collection @requests
  attributes :created_at, :updated_at, :user_id, :request_type

show.json.rabl:

object @request
 attributes :id

The first route i.e. :index returns the array of Request objects nicely but the second route i.e :show throws the following error:

NoMethodError at /show/1
undefined method `head?' for #<Request:0x007f6814485840>

Can someone point at what this error could be about? Why is it looking for head? function?


Solution

  • Don't use @request instance variable. Rack stack uses it to store HTTP request there.