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

3

5

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?

Unfinished answered 31/12, 2012 at 15:6 Comment(11)
can you give particular example?Appointee
When I make ANY change to the code in a model I have to restart the server or the app runs as if there was never any change.Unfinished
did you add config.threadsafe! in application.rb or development.rb ?Appointee
if you are adding models to the rails app then you may have to do a rake db:migrate first, I don't believe there is any way to get around that.Icosahedron
not adding models. just changing callbacks.Unfinished
Did you try running rails server -e development, just to make sure you are in your development enviromentIcosahedron
Yes. RubyMine has added that automatically. Please see my edit.Unfinished
well is the problem only happening in ruby mine or is it does it occur when you run rails app from the command lineIcosahedron
if makesandwich isn't a model then it you should proably go to a lib folder or something simular this this stackoverflow answer whould proably help https://mcmap.net/q/116096/-oo-design-in-rails-where-to-put-stuffIcosahedron
Have you tried all this: (1) Run webrick outside of Rubymine. (2) Edit file in some normal editor, save and reload page - check if you change too effect. (3) Create a new rails app and start at step 1.Angular
Thanks @EugeneRourke that was a real head scratcher for me until I realized that I'd turned on config.threadsafe! to test something in development and hadn't taken it outPsychodrama
U
0

The problem was that I put a function in a separate file and was editing the function there. This will work fine for production, but for development purposes I put the function back in to the Lesson.rb file and the refreshing started working properly.

Unfinished answered 9/1, 2013 at 13:5 Comment(0)
S
11

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

Stacey answered 10/7, 2014 at 22:56 Comment(1)
Life saver! Just figure out the clock inside VM is 3 minutes slower than the host one.Coryza
U
0

If you're working on a Rails 3 project, you might find Zeus helpful. It keeps track of the files in your project, and reloads only the changed code in memory. It makes REPL a lot quicker for Rails 3 development.

https://github.com/burke/zeus

Unimposing answered 4/1, 2013 at 18:34 Comment(0)
U
0

The problem was that I put a function in a separate file and was editing the function there. This will work fine for production, but for development purposes I put the function back in to the Lesson.rb file and the refreshing started working properly.

Unfinished answered 9/1, 2013 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.