...But we do need Rails. Because Rails is magic!
Well, OK, not exactly magic, but on first look Rails appears to be a very *magic code wand* style of framework for Ruby.
Because of it's design, and its emphasis on the use of software engineering patterns and paradigms, Rails encourages you to build RESTful (Representational State Transfer, a software architecture style for building scalable web services) applications. So if you make use of the facilities inside of Rails, like Scaffolding which can automatically construct some of the models and views needed for a basic website, all the code generated in Rails is building a RESTful application. Rails has even been described as "REST out of the box".
We could look at Rails as being a little bit like the default factory settings offered to you when you install software. Of course you always have the option of picking and choosing which files you want, and manually configuring your install - but really, who has the time for that? So when it comes to setting up your new application Rails will do the job for you thanks to it's use of Convention over Configuration, this also means that generally Ruby on Rails conventions lead to less code and less repetition.
And that's gotta be good, right?
OK, so Rails has now set everything up for you nicely, let's take a look 'inside the box' and discover how Rails processes an incoming request.
We'll break it down into stages:
- The client requests the page.
- The request is parsed (divided into parts and analysed) by the router to identify a particular method (action) somewhere in the controller code.
- The router takes the first part as a controller name.
- The router takes the second part as a method name (action).