I need to have access to current_user_id from within ItemSerializer.
Is there a way to achieve it? I am fine even with a dirty hack :)
I know about existence of serialization_options hash (from How to pass parameters to ActiveModel serializer
) but it works only with render command (if I am right) so it's possible to do:
def action
render json: @model, option_name: value
end
class ModelSerializer::ActiveModel::Serializer
def some_method
puts serialization_options[:option_name]
end
end
but in my case I use ArraySerializer to generate a json hash outside of render command like so:
positions_results = {}
positions_results[swimlane_id][column_id] =
ActiveModel::ArraySerializer.new(@account.items,
each_serializer: ItemSerializer,
current_user_id: current_user.id) # <---- Does not work