Pass rails method(association) to React Js

南笙酒味 提交于 2019-12-12 06:09:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!