How to extract all attributes with Rails Jbuilder?

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

    In case if you want to exclude any of the attributes. Ex: created_at and updated_at

    json.merge! notification.attributes.reject{ |key, _| key.in?(['created_at', 'updated_at']) }
    

提交回复
热议问题