How to extract all attributes with Rails Jbuilder?

前端 未结 6 1156
無奈伤痛
無奈伤痛 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:47

    I'm using jbuilder 1.5.0 and merge! didn't work but I found an alternative syntax:

    json.(notification, *notification.attributes.keys)
    

提交回复
热议问题