Total I have the following code:
def search
@regions = Region.search(params[:searchPhrase]).page(params[:current].to_i).per_page(params[:rowCount].to_i)
data = {
current: @regions.current_page,
rowCount: @regions.per_page,
total: @regions.count,
rows: @regions
}
respond_with(data)
end
This gives me an output like:
{total: 20, current: 2, rowCount: 10, rows: [{id: 1, name: "Region"}, ...]}
This works fine, but I want the same format all over the application.
I've read some content about ActiveModel Seralizers gem, but I couldn't find a way of doing this the following:
- Addind a root with a custom name. I know I cant set a root with AMS, but how can I name it?
- Adding keys for a CollectionSerializer. I know I can use meta, but I don't want to keys to be under another key. I want the output as it is today.
Does anyone knows how to achieve this?