Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Lonnie Parker
Lonnie Parker
5,964 Points

Automatic Rails migration issue

I have run through the ToDo application in Rails on multiple platforms. In Windows, Linux, and now VM on Windows. I've noticed that in Windows and Linux, I was able to follow the video instructions, making changes to the code (while running the rails server), refreshing my browser, and see the impact my change to the code had on the displayed page. Since starting to use the VM in Windows, I've noticed that each time I make a change to the code, in order to see the changes reflected in the behavior of the application, I need to:

1) Stop the server 2) Run the "bin/rake db:migrate" and "bin/rake migrate RAILS_ENV=test" commands 3) Restart the server

I never had to do this before when running in Linux or Windows. I could just make changes to the code on the fly (while the server was running) and see the changes reflected right away. Is there a missing gem I need to install? Any thoughts? Thanks!

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

If you make any changes in your models or with anything related to the database (and migrations are related to models and database), you have to restart the server.

Lonnie Parker
Lonnie Parker
5,964 Points

Thanks Maciej! But just to clarify, does 'restarting the server" also presume you need to run the rake:migrate/rake migrate RAILS_ENV=test commands as well? Just wondering why I was able to see changes made in code reflected on the fly without restarting the server when running examples in linux or windows, but not the VM. Thoughts?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Did those changes involve models, databases and/or migrations? If so, it's weird :). It shouldn't just work in the browser without at least stopping and starting the server.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

rake db:migrate is needed only if you introduce a new migration file, reset the database or run a copied/downloaded project for the first time.

Lonnie Parker
Lonnie Parker
5,964 Points

Ok, thank you, I confirmed what you were saying. Now I see that I only need to restart the browser.

If I recall correctly, it was related to the video "Write Our First Tests" at the 7:00 mark that covered how to add validations to ensure that the written tests do not fail. After adding the necessary validation code to the model (todo_list.rb), all that was needed (when working in linux and windows) was to reload the browser while the server was still running, but since working in the VM, I've had to restart the browser to see the changes reflected in the application's behavior. I guess my only question now is: Does Jason restart the server, but without mentioning it in the video?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I don't know, it is probable. The video only encompasses a part of his screen and there are numerous cuts in the videos, so we don't see everything. I usually restart the server every time, even if I do some simple changes, just in case, to be 100% sure that ALL my changes were loaded to the environment. I work on dedicated Ubuntu machine and sometimes on VMWare virtual machine.