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

[Issue #13] Add render syntactic sugar #15

Merged
merged 1 commit into from
Jun 19, 2014
Merged

Conversation

zph
Copy link
Contributor

@zph zph commented Feb 9, 2014

As in issue #13 an example solution provided by @jrhe an implementation
of said feature has been created.

As per the discussion in the thread this is only a helper to be able to
reach the available options provided in the active_model_serializer gem.

usage is as follows:

get '/some_path' do
  collection = Collection.all
  render collection, { meta: { current_page: 5 }, meta_key: :pagination_info }
end

The return value would be:
{ pagination_info: { current_page: 5 }, collection: [item, item] }

If given without a meta_key it would return as:
{ meta: { current_page: 5 }, collection: [item, item] }

Any feedback appreciated.

@zph, @olleolleolle and @bjoska

As in issue ruby-grape#13 an example solution provided by @jrhe an implementation
of said feature has been created.

As per the discussion in the thread this is only a helper to be able to
reach the available options provided in the active_model_serializer gem.

usage is as follows:

```ruby
get '/some_path' do
  collection = Collection.all
  render collection, { meta: { current_page: 5 }, meta_key:
    :pagination_info }
end
```

The return value would be:
`{ pagination_info: { current_page: 5 }, collection: [item, item] }`

If given without a `meta_key` it would return as:
`{ meta: { current_page: 5 }, collection: [item, item] }`

Any feedback appreciated.

@zph, @olleolleolle and @bjoska
@rahilsondhi
Copy link

👍 This is very useful.

@rahilsondhi
Copy link

Problem: If the collection is empty, the JSON returned is simply [] without metadata. I'm expecting the metadata to still be there even if the collection is empty.

@jrhe
Copy link
Member

jrhe commented Jun 19, 2014

Not sure if this is the best way to do things but its tested and I haven't had time to redo it myself so I will merge it as people seem to want it.

jrhe added a commit that referenced this pull request Jun 19, 2014
[Issue #13] Add render syntactic sugar
@jrhe jrhe merged commit cfc6a02 into ruby-grape:master Jun 19, 2014
@bjonord
Copy link

bjonord commented Jun 19, 2014

Hi @jrhe,
Glad to see this getting merged, but would love to get input on how you would have preferred it to be done? Maybe I can find time to rewrite in a better way given some guidance. 😄

Thanks for taking the time to review and merge it!

@jrhe
Copy link
Member

jrhe commented Jun 19, 2014

@bjoska, I was thinking that we could somehow proxy ALL options passed to render through to AMS. There are other options like serializer, each_serializer, scope etc which this doesn't support. See issue #13. Haven't looked at the code for a while so I'm not sure how feasible this is. May have some time to look at it next week but if you want to take a look feel free :D.

@bjonord
Copy link

bjonord commented Jun 19, 2014

@jrhe¸ I'll see what I have time for. Think we had a look at proxying but it didn't pan out as we had hoped. :(

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

Successfully merging this pull request may close these issues.

4 participants