Rails in production and code reloading

When I have discovered Rails through 4 Days on Rails over a year and half ago, I decided to buy Agile Web Development with Rails, which is great book for learning Rails. And there I found following statement (page 52):

It turns out that the WEBrick-based Rails dispatcher is pretty clever. In development mode (as opposed to testing or production), it automatically reloads application source files when a new request comes along. That way, when we edit our application, the dispatcher makes sure it?s running the most recent changes. This is great for development.

This is true, but You have to remember what application source files mean in this context. As I wrote earlier reloaded are files from app directory (and at least part from config since changes in routing are in effect without restart). Code in lib is not reloaded.

Well this I have knew from long time, but yesterday I have learned something new (for me) about Rails in production mode. From quote above I was thinking production server does not re-read code from app directory at all. Boy, I was wrong.

First, I discovered very stupid error in Run-N-Share. I used embedded map to present info how to get to Bootstrap meeting (polish web site). Bootstrap is our monthly local meetup, where we discuss new trends, technologies and people share with own experiences running business in web 2.0 world.

I draw a route used code presented on page to embed it on Bootstrap blog and… I saw this route. What the heck?!? Quick look in RNS code and I found my stupid mistake – I did not create link to copy and paste with real route ID, I have just hard coded link to widget with ID 1. Grrrr… I made quick fix, deployed code to production site. Reloaded webpage without app restart. And saw that production server have noticed change in RHTML template without restart.

Production server does cache only real Ruby code and RHTML templates are just plain data files in this context. So any change made in RHTML template is in effect without application restart…

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.