Smam Smam - 4 months ago 11
Ruby Question

Is there any way to hide attributes in a Rails Jbuilder template?

I know you can explicitly list fields like so,

json.(model, :field_one, :field_two, :field_three)


But is there anything similar to the following,

json.(model, except: :field_two)


which would output all of the model fields except the one called out?

Answer

Try json.merge! model.attributes.except("field_one", "field_two")

Comments