ccocchi / rabl-rails

Rails 4.2+ templating system with JSON, XML and Plist support.
MIT License
209 stars 51 forks source link

nil is not a Symbol #24

Closed Tonkpils closed 11 years ago

Tonkpils commented 11 years ago

I ran into this issue when I went into production and tested in both small and big apps in development.

controller

def list
  @client_applications = @account.client_applications.page(params[:page]).per(params[:per_page])
   @message = "Application list"
    render 'client_applications/index', status: :ok
end

index.json.rabl

object false

node(:client_applications) { partial('client_applications/_show', object: @client_applications) }

extends 'shared/success'

I made a request a request to the list action and this was the output the first time. Server

Processing by Api::Web::V1::ClientApplicationsController#list as JSON
  Parameters: {"account_id"=>"5"}
  Account Load (0.6ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = 5 LIMIT 1
  ClientApplication Load (0.4ms)  SELECT "client_applications".* FROM "client_applications" WHERE "client_applications"."account_id" IN (5)
   (0.6ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "client_applications" WHERE "client_applications"."account_id" = 5 LIMIT 25 OFFSET 0) subquery_for_count 
  Rendered client_applications/index.json.rabl (5.0ms)
   (0.4ms)  SELECT COUNT(*) FROM "client_applications" WHERE "client_applications"."account_id" = 5
  CACHE (0.0ms)  SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "client_applications" WHERE "client_applications"."account_id" = 5 LIMIT 25 OFFSET 0) subquery_for_count 
Completed 200 OK in 244ms (Views: 16.5ms | ActiveRecord: 12.5ms)
{
    "account_id" => "5",
        "format" => "JSON",
    "controller" => "api/web/v1/client_applications",
        "action" => "list"
}

Response

{"status":"success","message":"Application list","client_applications":[]}

I made a second request to the same action and this was the output. Server

Started POST "/private/applications/list" for 127.0.0.1 at 2013-01-24 14:23:54 -0500
Processing by Api::Web::V1::ClientApplicationsController#list as 
  Parameters: {"account_id"=>"5"}
  Account Load (0.4ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = 5 LIMIT 1
  ClientApplication Load (0.4ms)  SELECT "client_applications".* FROM "client_applications" WHERE "client_applications"."account_id" IN (5)
  Rendered client_applications/index.json.rabl (47.4ms)
Completed 500 Internal Server Error in 62ms

ActionView::Template::Error (nil is not a symbol):
    1: object false
    2:
    3: node(:client_applications) { partial('client_applications/_show', object: @client_applications) }
  app/views/client_applications/index.json.rabl:2:in `_app_views_client_applications_index_json_rabl___1939161566045685585_70366142492940'
  app/controllers/api/web/v1/client_applications_controller.rb:151:in `list'

Any subsequent request returned the same error. I restarted the server and it allowed me to make one request with a successful response and rest became errors again.

The trace showed the error pointing to this line in rabl-rails

[PROJECT_ROOT]/vendor/cache/rabl-rails/lib/rabl-rails/library.rb, line 18

238855 commented 11 years ago

Hi I am experiencing the same 'Nil is not a symbol' issue in development.

controller

def index
    @person = current_user.person
     respond_with(@person)
end

index.rabl

collection :@person
attributes :uid, :full_name, :gender, :mini_bio, :birthday => :dob

I have check the @person variable and it is a full object. This was working with no problem yesterday and I cannot figure out where I am now going wrong. I have attempted to undo changes and get back to working version but no luck.

Type error on Line 18 also:

{LOCAL_PATH}/rabl-rails-0.3.0/lib/rabl-rails/library.rb:18:in `const_get'
Tonkpils commented 11 years ago

@justmatt Can you double check your format parameter in your application. For some reason, my format was getting upcased somewhere along the request. I posted a fix for this #25

238855 commented 11 years ago

@Tonkpils Yea thanks, that fixed the problem! I left some comments on you code ( I can't be bothered to submit a pull request). Appreciate you taking the time to reply to me; wouldn't have got this without your encouragement