Render :json with extra data

前端 未结 3 813
星月不相逢
星月不相逢 2020-12-30 08:43

I have a model called Todo and I render this:

format.json { render :json => @todo }

Each Todo belongs_to a List. I want to add the value

3条回答
  •  死守一世寂寞
    2020-12-30 09:19

    To refine Brandon's answer, try using:

    render :json => @todo.attributes.merge({list: { "completion_percentage" => 63 }})
    

提交回复
热议问题