Why does code need to be reloaded in Rails 3?

后端 未结 2 777
不知归路
不知归路 2020-12-06 03:33

I am a former PHP developer learning Rails and Sinatra. In PHP, every page request loaded all of the required files. If I changed some code and refreshed the page, I could b

2条回答
  •  日久生厌
    2020-12-06 03:45

    How about a more high level approach:

        ActionDispatch::Reloader.cleanup!
        ActionDispatch::Reloader.prepare!
    

    This was taken from Rails/ActiveRecord v3.2.13 - active_record/railtie.rb

    The load approach didn't work for me. Just performing load caused a weird issue where it would trigger certain validators twice for me.

    In order to fix that, I tried Object.send(:remove_const, User) before reloading User, but then I lost my observers on that class, so I started chasing my tail.

    The above approach reloads all the classes, so maybe there is still yet a better approach to properly remove an individual class from cache and reload it...

提交回复
热议问题