Include has_many results in REST JSON result

后端 未结 1 2041
北海茫月
北海茫月 2021-02-07 21:14

I have a Model called List that has_many :entries. As usual, Rails 3 generated this show method for List

def show
    @li         


        
1条回答
  •  醉梦人生
    2021-02-07 22:03

    Yes, there's an :include option you can give to to_json:

    format.json { render json: @list.to_json(:include => :entries) }
    

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