Reload the rails console

落爺英雄遲暮 提交于 2019-11-30 08:10:31

Yes, you need to call reload! as this will clear the loaded constants that have been loaded and will load them as they're referenced in the console.

If you have old objects from before the reload! you will need to call reload on these individual objects or find new objects and work with them if you want to try out the new method.

As an alternative, I would really recommend looking into a testing framework such as RSpec which gives you repeatable tests and a safety net for your application.

It looks like you're trying to use the console as a testing tool for new functionality in your application, which is what RSpec is better suited for. The console is really good for experimentation.

daicoden

rails console does not reload classes after they have been referenced.

If it did it would have to make a call out to the file system to figure out which files had changed for every command.

rails server on the other hand will reload changed classes in between requests in development mode.

I'm guessing you are keeping the console open due to the rails console start up time. I'm not sure what your application is, and am unsure as to why the console is open during development. However, if you are trying to verify changes might I recommend testing with unit test or rspec and at that point you can use spork to speed up the start up time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!