how to append data to json in ruby/rails?

后端 未结 6 849
南方客
南方客 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:47

    Have you tried this ?

    item = Item.find(params[:id]) 
    item <<{ :status => "Success" }
    
    render :json => item.to_json
    

提交回复
热议问题