Search code examples
ruby-on-railsrubyjsonruby-on-rails-5jbuilder

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?


Solution

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