Ruby On Rails
This is it, the moment we have all been waiting for – Rails week. Everything has been leading up to this week for me. It has been a really wild ride so far. In only 4 short months I have gone from knowing essentially nothing about coding to building web apps from scratch. Reflecting on my past understanding has really put things into perspective for me. No matter how much of a noob I feel like today, by comparison to where I began 4 months ago – I am a master coder.
On to the content of the week, which could be summarized into a single word – shortcut. Rails is one giant shortcut for developers and I, for one, am very grateful for it. Rails is a framework built on the Ruby language and it adheres to a principle known as convention over configuration.
What does this mean? Essentially, the creators of Rails decided from the outset what the best way to build a web app would be and so they configured it to have certain defaults. The power behind rails comes from adhering to the built in assumptions. They are often simple, like is that file name singular or plural? Rails notices. Where are you putting your routes file? Rails notices.
When it comes to convention over configuration, why is it important and why do people care? Well, I have been able to see, first hand, this week why that is and it is this – Rails offers a level of efficiency and speed that isn’t typically found elsewhere. Adhering to rails convention could see you having a website up and running by the end of the day, if you’re good enough.
Rails preloads a whole host of files and folders for you that are already configured in such a way that you can begin creating right away. Running
rails new insert-project-name will give you this new working folder with all the accoutrements.
Here is a look of a newly created Rails app called,
blog-project. I haven’t created a single thing, this is everything that Rails give you to begin your project. As one of my instructors says – more files, more good!
Now, let’s take a look at how all of that is working in tandem. In order to understand Rails you need to understand how it functions. Rails uses RESTful design and MVC – Model, View, Controller. Let’s break this down.
- The user directs to a url path (e.g.
routes.rblooks for a corresponding controller to handle this
- The controller looks to the corresponding model, which models the
objectfrom the database
- The database object is sent back to the controller, through the model and then outputted from the controller to the views folder, where an HTML representation will be put on the screen.
In the world of MVC, the Controller is doing the majority of the heavy lifting. It is constantly listening, based on user interaction, for requests from the user. The controller, after being given the ‘green light‘ by the
routes.rb file, will organize and output all necessary data based on what the user is asking for. In this way, the controller is our point man, it makes sure everything happens in the way we want it to.
I will dedicate a few articles to the specifics of Rails, as there is a lot to unpack there but for now we will move on. As far as impressions for the week are concerned, I am thrilled to be learning rails. It has been a godsend – everything is simpler, quicker, cleaner and more efficient.
For some, the idea of having to conform to the assumptions of the rails framework is more than an annoyance, it is a hindrance – but I don’t see it that way. I like to think of it like this – If I can only adhere to the way Rails is structured, I can leverage its power to do more of the work for me. With this in mind, I am now able to transfer what would have been wasted time and energy into more constructive areas such as design, UX & Testing among other things.
My recommendation for those who are unfamiliar with Rails is this – If you have a solid understanding of Ruby then you should feel comfortable navigating through the Rails documentation. If you do not have a solid understanding of Ruby or are otherwise a novice to programming in general, I recommend you stay away from Rails for a little bit or at least until you are capable of building simple web apps in Sinatra.
Another thing I have noticed after getting into rails is the documentation – it’s freakin awesome.
The documentation is so well written and organized that in just one weekend you could likely get a firm hold on the Rails concepts by just reading through it all.
In fact, I did just that this past Tuesday. I was suffering from a bout of insomnia and decided to make the most of my time so I built a simple blog based on the instructions in the provided tutorial. It walks you through starting a project from scratch all the way up to hosting it on a server (
localhost:3000). I highly recommend this to everyone interested in Rails!
With the power of rails now in my back pocket, we move into Group Project mode, which is 2 weeks long. This is followed by an additional 2 weeks of solo projects, called Breakable Toys by Launch Academy. I already have a solid idea for my Breakable Toy and will break ground on it this weekend.
I am really looking forward to group projects because I feel like I will learn so much more than I already have. Collaboration is such an amazing way of learning – you get to watch how other people tackle problems. It may seem trivial but just that alone is enough to jar your mind into thinking of problems in a completely different way. Often times, this is when the greatest breakthroughs of understand and comprehension occur.
Watch out for more in depth articles in the coming week on the intricacies of Ruby on Rails and everything in between. Until then, happy coding friends!