0
    render :json => @bs.to_a.to_json, :except => ["completo"]      

I want to render everything to json except the field "completo". That should be working but given that I need to do ".to_a" and ".to_json", that stopped working. Is there a way to revert that?

Thanks

Donald
  • 243
  • 4
  • 10

1 Answers1

0

Assuming that @bs is a MongoDB Cursor, do the following:

@bs = @bs.to_a.map { |obj| obj.delete("completo"); obj }
render :json => @bs.to_json

In summary:

  1. Make it an array.
  2. Remove the completo key from every item in the array, making sure we return the item itself at the end of the map
  3. Render as before.
Douglas F Shearer
  • 25,952
  • 2
  • 48
  • 48