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

set scope from params #13

Closed
AlessioRocco opened this issue Nov 13, 2013 · 7 comments
Closed

set scope from params #13

AlessioRocco opened this issue Nov 13, 2013 · 7 comments

Comments

@AlessioRocco
Copy link

I need to set the serializer scope from the params, I'm trying like that:

get ':id', scope: { showings: params[:showings] } do
  Movie.find(params[:id])
end

but params is not yet defined.

Is there way to do that?

@jrhe
Copy link
Member

jrhe commented Dec 19, 2013

I think there isn't a way to do this currently. I think what this needs is an alternative syntax for configuring GAMS. The way I was thinking of is having a render helper to make the syntax similar to how you'd use AMS in rails. i.e.

get ':id' do
  render json: Movie.find(params[:id]), scope: { showings: params[:showings] } 
end

This should solve your problem as it would bring params in scope. Thoughts?

@SynnaxCrab
Copy link

+1 for this, i have an api which need to present results from sunspot search. i want to include a meta like { total: search.total }

@jrhe
Copy link
Member

jrhe commented Dec 31, 2013

I was planning on doing this but my laptop has died and is in for repair. If you want to pick it up and submit a PR feel free otherwise it will e a couple of weeks.

Kind regards,
Jonathan Evans

Sent from my phone.

On 31 Dec 2013, at 07:34, À´Åµ [email protected] wrote:

+1 for this, i have an api which need to present results from sunspot search. i want to include a meta like { total: search.total }

¡ª
Reply to this email directly or view it on GitHub.

@SynnaxCrab
Copy link

Thanks, @jrhe . Happy new year!

i found a workaround using Grape's present. looks like not a bad solution.

@jrhe
Copy link
Member

jrhe commented Jan 10, 2014

Could you post your solution here? It might be the same syntactic sugar I
described above with 'render'. Cheers

On 2 January 2014 08:38, 来诺 [email protected] wrote:

Thanks, @jrhe https://github.com/jrhe . Happy new year!

i found a workaround using Grape's present. looks like not a bad solution.


Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-31441736
.

@SynnaxCrab
Copy link

i was just using grape's present method

something like

present :song_count, song_search.count
present :songs, song_search.results

song_search.results is a collection of Song model instances

@bjonord
Copy link

bjonord commented Feb 7, 2014

Would love to see something like this

👍

zph added a commit to zph/grape-active_model_serializers that referenced this issue Feb 9, 2014
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
zph added a commit to zph/grape-active_model_serializers that referenced this issue Feb 9, 2014
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
jrhe added a commit that referenced this issue Jun 19, 2014
[Issue #13] Add render syntactic sugar
@jrhe jrhe closed this as completed Jun 19, 2014
@jrhe jrhe reopened this Jun 19, 2014
jrhe added a commit that referenced this issue Jul 23, 2014
* 'master' of github.com:jrhe/grape-active_model_serializers:
  fix: when resource is empty, keep json resource root
  support active model serializer 0.9.x
  [Issue #13] Add render syntactic sugar
@jrhe jrhe closed this as completed Nov 21, 2014
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

No branches or pull requests

4 participants