Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error trying to cache RABL views #413

Open
andrewhubbs opened this issue Feb 20, 2013 · 5 comments
Open

Error trying to cache RABL views #413

andrewhubbs opened this issue Feb 20, 2013 · 5 comments

Comments

@andrewhubbs
Copy link

The basic error I am getting is this:

ActionView::Template::Error (no _dump_data is defined for class Proc):
    1: object @companies
    2: extends "companies/show"
  app/views/companies/show.json.rabl:5:in `block in render'
  app/views/companies/index.json.rabl:1:in `_app_views_companies_index_json_rabl___4497490218609257421_70338596442820'

My views look something like this:

# companies/index.json.rabl
object @companies
extends "companies/show"

# companies/show.json.rabl
object @company
attributes :name, owner_id, :id, :created_at, :updated_at
node :employees do |company|
  partial "employees/index", object: company.employees
end
# ...

# employees/index.json.rabl
collection @employees
extends "employees/show"

# employees/show.json.rabl
object @employee
cache [root_object, root_object.teams] # << Only cache line in project

attributes :email, :roles, :icon_url, :name, :phone_number, :id, :created_at, :updated_at
node :teams do |employee|
  partial "teams/index", object: employee.teams
end
# ...

Any thoughts on what is going on here?

Relevant config:

# RABL config
Rabl.configure do |config|
  config.cache_engine = Rabl::CacheEngine.new # Defaults to Rails cache
  config.include_json_root = false
end

# Rails config
App::Application.configure do
  config.action_controller.perform_caching = true
end
@andrewhubbs
Copy link
Author

This may be a bug in Rails. The error is very similar to this bug and changing the objects I am passing into the partials into arrays seems to fix it.

cache [root_object, root_object.teams.to_a] # << Notice the `to_a`

node :teams do |employee|
  partial "teams/index", object: employee.teams.to_a # << Notice the `to_a`
end

Having to do this everywhere seems like a pretty lame solution. Any other thoughts?

@andrewhubbs
Copy link
Author

So after more digging I think it is a little more complicated. I have narrowed it down to a specific has_many relation between a few of my models. The relation looks something like this:

class Employee < ActiveRecord::Base
  has_many :assigned_items, class_name: ChecklistItem, finder_sql: Proc.new {
    %Q{
      SELECT "checklist_items".* FROM "checklist_items"
      INNER JOIN "checklists" ON "checklists"."id" = "checklist_items"."checklist_id"
      WHERE "checklist_items"."employee_id" = #{id} AND "checklist_items"."active" = 't' AND "checklists"."active" = 't'
      ORDER BY "checklist_items".created_at
    }
  }
end

Looks like the finder_sql is the real culprit here. The to_a solution above doesn't seem to do the trick either.

@andrewhubbs
Copy link
Author

While their could be a problem in Rails, I am starting to think this is a RABL issue with writing cache values that can't be fetched back out. See the issue, referenced above this comment too.

@jharbert
Copy link

jharbert commented Nov 5, 2013

@andrewhubbs did you ever find a solution to this? I'm running into the same issue

@NoumanShahid
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants