Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my rails development environment not reloading on changes to code?

Each time I make changes to code I have to restart the server or it won't change the output.

I have tried using thin and webrick.

My development.rb file says "config.cache_classes = false".

I am using RubyMine.

Sometimes my view updates, but the models never update.

Anything else you need to know to help me troubleshoot this problem?

EDIT:

I am away from my coding machine right now, but I started thinking. I have a file called makesandwich.rb in app/models directory and app/models/Lesson.rb calls a function in that file. I have been making changes to the makesandwich.rb file and it hasn't been reloading. Do I need to add that file or should it be included automatically in reload?

like image 920
webmagnets Avatar asked Dec 31 '12 15:12

webmagnets


People also ask

How do I run rails server in developer mode?

Go to your browser and open http://localhost:3000, you will see a basic Rails app running. You can also use the alias "s" to start the server: bin/rails s . The server can be run on a different port using the -p option. The default development environment can be changed using -e .

How does Rails know which environment?

Rails reads the current environment from the operating system's environment variables by checking the following in order of priority: Get the value of the RAILS_ENV environment variable by calling ENV["RAILS_ENV"] If the above is nil, then get ENV["RACK_ENV"] If the above is nil, then make it equal to "development"


1 Answers

I recently had this problem as well. As others have said, it can be caused by setting config. cache_classes or config.threadsafe! to true, which will probably be the problem in most cases.

However, my problem was caused by running rails on a VM. My code was stored on a folder on my host machine, which was then mounted to the VM. Unfortunately, the clock time of my host machine was out of sync with the VM. Here's what would happen when I modified my code:

  1. I'd change some code in a text editor on my host machine
  2. Saving the code would set the modified time of the file to the current time for my host machine
  3. This time was in the future, from the perspective of the VM
  4. When the file update checker looked for modified files, it ignored my file since the modified date was in the future

Again, this is probably a pretty rare case, but it's worth checking this if you're running rails on a VM

like image 116
laurie Avatar answered Nov 16 '22 07:11

laurie