In my journey to hopefully master Ruby on Rails, I’m amazed to see that many authors (in blogs or in books) most of whom are pretty expert in the field, choose to exit the Rails console completely (using CTRL+D) when they need to restart the environment (to clear up the objects in the memory, for example).
Instead there is a convenient method:
reload! |
that you can type inside Rails console and it will reload the environment for you. No need to wait extra second to exit and reenter the console.
P.S. There might be a wisdom in not choosing realod!
which I might not be aware of. In that case please enlighten me in the comments.
Paolo
It only reloads the code, no changes in the attributes of models
http://gilesbowkett.blogspot.it/2007/08/evil-rails-console-gotcha-reload.html
Anyway it’s fine if you’re debugging some code and want to see how changes play out.
Ali
Actually it does reflect the model changes. 🙂
I ran a migration after the first
Image.new
. That removed theproduct_id
and areload!
, unless this is not what you mean.Sampson Crowley
reload! only reloads application code, not configs or anything environment related