I have a controller method drop_down_values
in which I select a set of values and respond in json ,building the object using a serializer. I am using FastJson Api. I want to know , how can I access other variables present in the controller in the serializer.
def drop_down_values
@drop_down_values = IndustrySectorList.all
@values = @drop_down_values.pluck(:industry_sector)
render json: DropDownValueSerializer.new(@drop_down_values).serialized_json
end
I need to use the @values
variable in the serializer. How can i pass this to serializer? I am not able to directly access this variable in the serializer.
Serializer:
class DropDownValueSerializer
include FastJsonapi::ObjectSerializer
attributes :id
end
Stack & version -
- Rails - 5.2.1
- Ruby - 2.5.1
- FastJsonAPI - 1.5