Hacker News new | past | comments | ask | show | jobs | submit login

Good to know: the lazy block is executed in a fiber, and fibers don’t share Thread.current.

It took me hours to debug why Rails I18n.locale was not honored inside the block.




Can you elaborate? What were you doing to the locale? Changing it?


Perhaps gp means that the i18n data was initialized as thread-local, so it was missing in other threads.


Rails uses I18n.locale as a "global variable" to store the locale of the request. Behind the scenes this is stored in Thread.current[]. So if you have a request that sets the locale to non-default one and you perform some work inside a lazy block, I18n.locale will return an incorrect value inside that block.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: