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?
Try json.merge! model.attributes.except("field_one", "field_two")
I had done something like this. Get an array of all desired attributes of model
model.attributes.keys.map { |key| key.to_sym } - [:field_one, :field_two]
Which can be written like
model.attributes.keys.map(&:to_sym) - [:field_one, :field_two]
Then splat the array while passing in jbuilder
json.(model, *(model.attributes.keys.map(&:to_sym) - [:field_one, :field_two]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With