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?

webmagnets
  • 2,266
  • 3
  • 33
  • 60
  • can you give particular example? – Eugene Rourke Dec 31 '12 at 15:25
  • 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. – webmagnets Dec 31 '12 at 15:38
  • 1
    did you add config.threadsafe! in application.rb or development.rb ? – Eugene Rourke Dec 31 '12 at 15:44
  • 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. – Egryan Dec 31 '12 at 15:50
  • not adding models. just changing callbacks. – webmagnets Dec 31 '12 at 15:51
  • Did you try running rails server -e development, just to make sure you are in your development enviroment – Egryan Dec 31 '12 at 15:54
  • Yes. RubyMine has added that automatically. Please see my edit. – webmagnets Dec 31 '12 at 15:57
  • well is the problem only happening in ruby mine or is it does it occur when you run rails app from the command line – Egryan Dec 31 '12 at 16:00
  • 1
    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 http://stackoverflow.com/a/1071510/638216 – Egryan Dec 31 '12 at 16:08
  • 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. – Zabba Dec 31 '12 at 18:51
  • 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 out – concept47 Feb 08 '14 at 09:31

3 Answers3

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

laurie
  • 708
  • 6
  • 16
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

digitalronin
  • 636
  • 6
  • 18
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.

webmagnets
  • 2,266
  • 3
  • 33
  • 60