Git Product home page Git Product logo

Comments (4)

siong1987 avatar siong1987 commented on May 27, 2024

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.

mepatterson avatar mepatterson commented on May 27, 2024

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.

mepatterson avatar mepatterson commented on May 27, 2024

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.

siong1987 avatar siong1987 commented on May 27, 2024

cool. i am closing this issue now since you already figure it out :)

from grape-active_model_serializers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.