I see a very strange problem with a simple controller method. Either I'm missing something fundamental, or I'm facing an error. My bid is on the first.
I have a Thing model with a ThingController .
A Thing has two variables, name and display , both lines.
ThingController (code below) has a toggle_display method that toggles the display content between "on" and "off" .
The problem is that when I call this action, Rails finds the correct Thing , but @thing.display is zero. When I check the database, the value in the "display" column is correct.
The strange part is that when I uncomment the third line in the code below (i.e. access @thing.name to access @thing.display ), then @thing.display is ok - it's not zero and it has the value that I would expect. It is as if @thing.display correctly initialized after accessing @thing.name .
Any idea why I will see this very strange behavior?
def toggle_display @thing = Thing.find(params[:id])
source share