Topic: current_user on Active Model Serializer

I need to access the current user in a serializer. I read this post … erializers . Did the same but with no luck.

Any suggestions?

Re: current_user on Active Model Serializer

I'm pretty sure you'll find the answer in this railscast … erializers

Re: current_user on Active Model Serializer

actually i did follow that cast, but i have a few diferences, im using cache, and i cache all the json generated. Thous, my code is like this.

module Cacheable
  extend ActiveSupport::Concern

  def to_json
    Rails.cache.fetch self.cache_key do

  module ClassMethods

    # Cache key for tables
    def cache_key
      ActiveSupport::Cache.expand_cache_key "#{scoped.maximum(:updated_at).try(:to_i)}-#{scoped.count}"


i have seen in a place that this was used when declaring explisitely the active_model_serializer., :serialization_scope = > current_user).to_json 

but did not quite work either.

Im using Devise, and my ApplicationController stats like this. In the cast Ryan uses a stub and a helper method, suposingly the current_user is accesible in any controller (because of a custom helper that Devise provides). I dont quite get what i am missing.

class ApplicationController < ActionController::Base

  before_filter :set_locale
  before_filter :authenticate_user!