How to extract all attributes with Rails Jbuilder?

前端 未结 6 1159
無奈伤痛
無奈伤痛 2020-12-11 00:16

It\'s a pain to write codes like this all the time in jbuilder.json template:

json.extract! notification, :id, :user_id, :notice_type, :message, :resource_ty         


        
6条回答
  •  不知归路
    2020-12-11 00:56

    Maybe you can use json.merge!.

    json.merge! notification.attributes
    

    https://github.com/rails/jbuilder/blob/master/lib/jbuilder.rb#L277

提交回复
热议问题