I’m learning Ruby on Rails. Currently I’m doing basic development on my local machine. What happens when I run rails server in the terminal (OS X)? I’d just like to understand what the Rails architecture is doing and which Ruby scripts are run.
I’m learning Ruby on Rails. Currently I’m doing basic development on my local machine.
Share
One of the things
rails serverdoes is that it loads all the dependencies/gems required by your Rails app, or at least sets them up to be auto-loaded later when they are needed. This is sometimes called “booting” or loading the “Rails environment”. This is also done when you run other rails commands likerails consoleorrails runner.It also starts a web server named WebRick. The web server is a piece of ruby code that, when run, binds itself to a port (by default port 3000) on your computer and starts listening for incoming HTTP requests on that port.
When a request comes in (for example an HTTP GET request of a user loading your from page), the web server works together with rails to handle the request. I’m not sure exactly how the work is divided, but the web server should take care of the lower-level stuff like reading HTTP headers and rails should take care of figuring out what controller and action to route the request to (using your routes.rb file). I think the component of rails that does this work is called action_dispatch, and it is in the actionpack gem.