rabl icon indicating copy to clipboard operation
rabl copied to clipboard

include_json_root on a per view basis.

Open acarr-shopkeep opened this issue 11 years ago • 3 comments

Hello, I was wondering if there is current support (that I'm not seeing), for specifying whether or not a json root is included in each rabl rendering.

Solutions presented online are for a global setting:

Rabl.configure do |config|
  config.include_json_root = false
end

If not, are there any plans for support?

EDIT: It seems that this Pull Request is for the above issue? https://github.com/nesquena/rabl/pull/557

Thank you.

acarr-shopkeep avatar Jul 31 '14 10:07 acarr-shopkeep

I'm running into this same issue. We have had an api for a while that was built specifically for mobile apps. Now we're trying to use Ember with Ember-Data and it's out of the box default expectation of how your api should be formatted is causing us issues. If we had the ability to turn this option on/off per Rails action it would make things a lot simpler.

supairish avatar Sep 02 '14 16:09 supairish

Just of note, it does appear you can do something like this in your action

Rabl.configuration.include_json_root = true
render json: @object
Rabl.configuration.include_json_root = false

Not very sexy though

supairish avatar Sep 02 '14 18:09 supairish

if you are stuck with object_root true, a workaround is to use:

collection @object, object_root: false
attribute :id, :activity_id, :created_at, :updated_at
object :false

glue @object do
  attribute :id, :activity_id, :created_at, :updated_at
end

artworx avatar Sep 30 '14 17:09 artworx