|

Reloading Rails console without exiting

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.

Similar Posts

3 Comments

  1. Actually it does reflect the model changes. 🙂

    
    ruby-1.9.2-p290 :011 > Image.new
     => #<Image id: nil, title: nil, image_path: nil, created_at: nil, updated_at: nil, product_id: nil> 
    ruby-1.9.2-p290 :012 > reload!
    Reloading...
     => true 
    ruby-1.9.2-p290 :013 > Image.new
     => #<Image id: nil, title: nil, image_path: nil, created_at: nil, updated_at: nil> 
    

    I ran a migration after the first Image.new. That removed the product_id and a reload!, unless this is not what you mean.

  2. reload! only reloads application code, not configs or anything environment related

Leave a Reply

Your email address will not be published. Required fields are marked *