rubysherpas / forem

The best Rails 3 and Rails 4 forum engine. Ever.
http://forem.herokuapp.com
MIT License
1.55k stars 422 forks source link

Fixes class reloading issue #679

Closed cjbottaro closed 9 years ago

cjbottaro commented 9 years ago

This fixes the issue for me. Sorry, couldn't run specs because I don't want to install MySQL, but it seems like a pretty innocuous change.

Pretty sure bug was caused by something related to this: http://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoloading-and-require

Something about autoloading classes (in app/) requiring non-autoloading classes (in lib/). ¯(ツ)

cjbottaro commented 9 years ago

Fixes issue #675 for me.

radar commented 9 years ago

Haha this is great! I was just warning another developer about doing this kind of thing in a model and then it's pointed out that I've done it myself!!

The require call is only ran once, and so on the second request when it reloads the model it won't run it again. The solution is to do as you've done, or to require them with require_dependency which uses load or require depending on a config setting I forget the name of right now.

Thanks very much for the patch! Travis has run the tests and according to it the tests are fine.

I'll merge now!