Smam Smam - 1 year ago 83
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download