Comments (4)
check this out: http://railscasts.com/episodes/409-active-model-serializers?view=asciicast
see how they use current_user
in serializer.
from grape-active_model_serializers.
So I saw that rails cast and I've tried every permutation of serialization_scope and scope and creating an attributes override method in my serializer class. None of it seems to do anything at all. Maybe I'm missing some secret step with grape+ams? This rails cast is for ams in a rails controller. Is there something special I have to do to make it work in grape?
from grape-active_model_serializers.
UPDATE: So I think I figured it out. I had to do this inside my endpoint block:
desc "Get widgets"
get '/' do
_serialization_scope = :current_application
@widgets = Widget.all
@widgets
end
This is less than optimal, since I'll have to constantly do this in every endpoint I define. :( But I guess it works. Would be nice if there was a more straightforward way to allow a serializer access to a grape helper.
UPDATE 2: Okay, so I can move that _serialization_scope = :current_application
up to the root level of my Grape::API class, which is better.
UPDATE 3: Actually, looks like maybe I don't need that at all... just the delegate
bit in the serializer. How come this didn't work earlier today? Heh. :)
from grape-active_model_serializers.
cool. i am closing this issue now since you already figure it out :)
from grape-active_model_serializers.
Related Issues (20)
- not working on custom json response HOT 2
- API Versioning: Supporting Active Model Serializers namespacing HOT 4
- Changing adapter in AMS is not affected to output HOT 9
- Issues versioning serializers with Grape 1.4 master HOT 17
- Swagger documentation HOT 3
- Globally specify serialization adapter HOT 1
- Release v. next HOT 5
- Convert all AM keys from snake_case to camelCase HOT 3
- `include: '**'` option not working on serailizers HOT 8
- undefined method `deconstantize' for nil:NilClass HOT 11
- [grape 1.0.0] Json root does not exist in response.
- Custom formatted error messages HOT 1
- default_serializer_options no longer works HOT 1
- Array root documentation HOT 3
- Namespaces with associations HOT 2
- Documentation on the ErrorSerializer HOT 3
- Release v. Next
- How can I have a resource loaded in included (jsonapi format) ?
- Test failures about Hash#deep_dup missing HOT 2
- Custom Metadata not woking
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grape-active_model_serializers.