In My React js application I need to pass data of my Product
Model's association model(say "Taxon"
),i am doing it successfully using Active record serializer
as
ActiveModelSerializers::SerializableResource.new(object, options).serializable_hash
where i pass options
as all association relation.
i can get whole array of taxon objects as json,But I want something mentioned As following
i using rails as backed i am calling method like
Prodct.first.category.name
which gives => "mugs"
the method it calls is
def category
taxons.joins(:taxonomy).find_by(spree_taxonomies: { name: Spree.t(:taxonomy_categories_name) })
end
Which give specific taxon object,In rails its working fine
But i need to pass it to React
As json object(i am using React and Redux in front end)
Please help me to solve this.. let me know if i can provide any required information...
Edit
My Product Serilizer class
class ProductSerializer < ApplicationSerializer
attributes :id, :slug, :name, :description
has_one :master
has_many :images
has_many :variants
has_many :product_properties
has_many :taxons // Can I change something here.....?
end end
render json: {taxon: taxon, success: true}
– Verecategory
method from react then you need to call route from react and after completing the manipulation just render it from your category method, like above – VereProdct.first.category.name
how is this is a method. you need to provide more details with your respective controller, routes and model – Vere