# Why do I have to reload the Console

**URL:** <https://www.ruby-forum.com/t/why-do-i-have-to-reload-the-console/75292>\
**Category:** Rails\
**Created:** [November 8, 2006, 10:22pm UTC](https://www.ruby-forum.com/t/why-do-i-have-to-reload-the-console/75292 "2006-11-08T22:22:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bharat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@Bharat](https://www.ruby-forum.com/u/Bharat)\
**Post date:** [November 8, 2006, 10:22pm UTC](https://www.ruby-forum.com/t/why-do-i-have-to-reload-the-console/75292/1 "2006-11-08T22:22:35Z")

</div>

I am new to RoR and trying to learn my way around. I have Bruce Tate’s  
RoR Up And Running book and am using it to learn RoR.  
An example in chapter 2 page 34 shows how simple it is to add  
validation for table records. The example adds validation to the  
ActiveRecord model class Photo.rb as follows:

Class without validation:  
class Photo \< ActiveRecord::Base  
end

Class with validation:  
class Photo \< ActiveRecord::Base  
validates\_presence\_of :filename  
end

The MySQL table that this class is managing is as follows:

mysql\> select \* from photos;  
±—±---------+  
| id | filename |  
±—±---------+  
| 1 | Cat.jpg |  
| 2 | dog.jpg |  
±—±---------+  
2 rows in set (0.00 sec)

Now I am trying to test all this from RoR console as the book is  
instructing me to. It says to type in the following in the console  
photo=Photo.new  
photo.save  
At this point, the validation is supposed to kick in and I am supposed  
to get a false reply. Instead I got true and indeed, a new record with  
empty filename was saved to the photos table. I was wondering as to  
why the validation did not work until I spotted the text written in the  
book which said that I will have to restart the console to reload my  
changes. I did that and the validation started to work.  
Is there something that I don’t know? I thought that the development  
environment was supposed to reload your changes instantly. I know that  
it is true for the Web Server. Why do I have to exit the console and  
reload it to see my changes? Is there a better way to reload the  
environment without having to quit the console and having to retype  
“ruby script/console” and wait for it to reload?  
Thanks in advance for your reply.  
bharat

---

<div class="post-metadata">

**Author:** ![Bharat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@Bharat](https://www.ruby-forum.com/u/Bharat)\
**Post date:** [November 8, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/why-do-i-have-to-reload-the-console/75292/2 "2006-11-08T22:42:40Z")

</div>

Bharat,

You can reload a class by typing

load ‘classname.rb’

in the console…

Nathan

---

<div class="post-metadata">

**Author:** ![Bharat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@Bharat](https://www.ruby-forum.com/u/Bharat)\
**Post date:** [November 8, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/why-do-i-have-to-reload-the-console/75292/3 "2006-11-08T22:52:41Z")

</div>

Thanks Nathan. As you can tell, I am really new to Rails. Is there a  
place/book/tutorial where I can find answers for console related  
questions? I find the console to be very useful tool while learning  
and would like to know all the commands and tricks like the one you  
mention above.  
Regards,  
Bharat

---

<div class="post-metadata">

**Author:** ![Bharat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@Bharat](https://www.ruby-forum.com/u/Bharat)\
**Post date:** [November 8, 2006, 11:14pm UTC](https://www.ruby-forum.com/t/why-do-i-have-to-reload-the-console/75292/4 "2006-11-08T23:14:45Z")

</div>

On Wed, 8 Nov 2006, Bharat wrote:

> Is there something that I don’t know? I thought that the development  
> environment was supposed to reload your changes instantly. I know that  
> it is true for the Web Server. Why do I have to exit the console and  
> reload it to see my changes? Is there a better way to reload the  
> environment without having to quit the console and having to retype  
> “ruby script/console” and wait for it to reload?

Think of it this way… when you start console you are in _one_ session.  
Just like if you change a model in the middle of making a request via  
your  
browser, it’s not going to update. In other words, every instance of  
console is a “browser hit”.

You can type “reload!” and it will reload all the classes. This could  
invalidate some of your previously find’ed objects though so you might  
have to re-find them.

-philip

---

<div class="post-metadata">

**Author:** ![Bharat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@Bharat](https://www.ruby-forum.com/u/Bharat)\
**Post date:** [November 9, 2006, 3:00pm UTC](https://www.ruby-forum.com/t/why-do-i-have-to-reload-the-console/75292/5 "2006-11-09T15:00:58Z")

</div>

Thanks you all gentlemen for your helpful comments. I am going to  
enjoy being a part of RoR community.  
Regards,  
Bharat

---

<div class="post-metadata">

**Author:** ![Bharat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@Bharat](https://www.ruby-forum.com/u/Bharat)\
**Post date:** [November 8, 2006, 11:12pm UTC](https://www.ruby-forum.com/t/why-do-i-have-to-reload-the-console/75292/6 "2006-11-08T23:12:51Z")

</div>

Nathan L. wrote:

> Bharat,
> 
> You can reload a class by typing
> 
> load ‘classname.rb’
> 
> in the console…
> 
> Nathan

In development mode all the classes in your app get reloaded on every  
request. In the console, there is no request, so there is no reload.

You can however, simply type:

reload!

And your models and everything else should get refreshed.

---

<div class="post-metadata">

**Author:** ![Bharat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5fc32e/32.png) [@Bharat](https://www.ruby-forum.com/u/Bharat)\
**Post date:** [November 9, 2006, 4:33pm UTC](https://www.ruby-forum.com/t/why-do-i-have-to-reload-the-console/75292/7 "2006-11-09T16:33:26Z")

</div>

Nathan L. wrote:

> Bharat,
> 
> You can reload a class by typing
> 
> load ‘classname.rb’
> 
> in the console…
> 
> Nathan
