nesquena / rabl

General ruby templating with json, bson, xml, plist and msgpack support
http://blog.codepath.com/2011/06/27/building-a-platform-api-on-rails/
MIT License
3.64k stars 334 forks source link

Cant access instance in Rabl template with Grape #392

Open amrnt opened 11 years ago

amrnt commented 11 years ago

I'm using Rabl with Grape.

I have this view, but @comments is nil here!

object false

node :meta do
  {total: @comments.count}
end

child @comments => :data do
  attributes :id, :message
end

I use this as initial config:

Rabl.register!

Rabl.configure do |config|
  config.include_json_root = false
  config.enable_json_callbacks = true
  config.view_paths = [File.expand_path('../../../api/views', __FILE__)]
end

class RablPresenter
  def self.represent(object, options)
    Rabl::Renderer.new(options[:source], object, format: options[:env]['api.format']).render
  end
end
nesquena commented 11 years ago

Are you using https://github.com/LTe/grape-rabl that has been updated and you may want to see if that solves your issue. Also, whats the call from the RablPresenter from within your grape routes?

amrnt commented 11 years ago

LTe/grape-rabl works fine, but I was wondering why Grape not working with Rabl::Renderer