JBuilder dynamic keys for model attributes

后端 未结 1 1193
抹茶落季
抹茶落季 2020-12-29 05:04

I\'m trying to build a JSON file to access a product\'s variation via a variation code. Ideally, I could call variations.abcdefgh essentially asking to define a structure li

相关标签:
1条回答
  • 2020-12-29 05:44
    json.set! :variations do
      @variations.each do |variation|
        json.set! variation.product_code do
          json.(variation, :available, :price)
        end
      end
    end
    

    ^^ this should do it

    0 讨论(0)
提交回复
热议问题