include_json_root on a per view basis.
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.
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.
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
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