how to append data to json in ruby/rails?

后端 未结 6 853
南方客
南方客 2020-12-31 00:29

Say i have this short code:

item = Item.find(params[:id])
render :json => item.to_json

but i needed to insert/push extra information to

6条回答
  •  再見小時候
    2020-12-31 00:53

    I always use:

    @item = Item.find(params[:id])
    render json: { item: @item.map { |p| { id: p.id, name: p.name } }, message: "it works"  } 
    

提交回复
热议问题