Ran across a strange gotcha while working in Rails 3.0 today, having to
do with the
:only option to the
Let’s say you have a Widget on which you call
to_json. You don’t want
any of the widget’s attributes to appear in the JSON (maybe you only
want some method results). Normally, one would expect this to do the trick:
Strangely, this didn’t work. I found I needed to put a nil in the empty
:only array, like so:
for everything to work as expected.
This might have something to do with the fact that I’m using the json gem, but I haven’t had the time to dive into that.