问题
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
来源:https://stackoverflow.com/questions/44201299/pass-rails-methodassociation-to-react-js