I'd like to call my serializer (using ASM 0.8 from master https://github.com/rails-api/active_model_serializers/tree/0-8-stable ) like this:
def edit
@loc=Location.find(params[:id])
render json: @loc, serializer: LocationSmallSerializer, root: "data", meta: "success", meta_key: 'status', show_admin:true
end
Where the show_admin value will be generated on the fly so that extra fields in the api for admin will only exist for admin users.
The serializer will look something like this:
class LocationSmallSerializer < ActiveModel::Serializer
attributes :name, :show_admin, :admin_vals
def admin_vals
????
if @options[:show_admin]==true
add these attributes
end
end
How would I merge attributes in 'admin_vals' with the attributes from above? Or if better solution, what would it be?