In my next series of posts called A Taste of Ruby on Rails, I wanted to explain what I’ve been learning for the past couple weeks.
Well, when you talk about Ruby on Rails, you’re really talking about two separate things. Ruby is actually a programming language created by Yukihiro “Matz” Matzumato in 1993. If you don’t know what a programming language is, it’s basically written codes that talk to your computer or internet browser, like Google Chrome, and tells it what to do or to display. The difference between Ruby and other languages that I have been dealing with like php is that Ruby’s syntax, or programming grammar, was created to greatly reflect the English language. So unlike other code, which often times has more complex syntax, a person with a less technical background would be able to better understand what the language is supposed to do. This allows for both ease of reading and ease of learning. Because of these two things, the Ruby community has grown throughout the years and incorporates a number of different libraries. Libraries are large chunks of code that help to do certain functions, like logging into a site. These libraries, or Gems, are easily created and accessed by the vast Ruby developers around the world. It’s another reason why Ruby is such a popular language.
So that’s Ruby. What about Rails? Well, Rails is a framework built on Ruby to help developers. If you’re not a coder, you’re probably a bit confused right now.
Let’s use a metaphor. Ruby on Rails is used to build web applications, which are websites that take in information like your name, where you live, and the name of your puppy. Let’s compare the construction of a website to building a house.
So when you’re building your house, you have a blueprint of what you want your house to look like. This particular look of the house is called the view of the house. A view in Rails is similar to the view of the house, but instead of the look of the house, we’re talking about the look of the webpage or everything that is delivered to you that you can visually see.
Now, in order to create that view of the house, you’re going to either build the house yourself or hire a contractor to build it for you. This contractor is what we call the controller. In Rails, a controller looks at the view and sees what it needs to build. Then it gets ready to create what is required from the view.
When the contractor builds the house, he kind of has a general idea of the different things that he needs to build, like doors, windows, and walls. If he had a framework, he would have an example of what these things look like and how they are built. Or in essence, he would have a model. In Rails, the model is a representation of what you’re building. They go into something called a database that has data. Then it takes what it needs to create the model. In our house example, this would be like a contractor seeing that he needs a particular type of wood to build his model of a door. These are his resources, and that’s what Rails’ models deal with. Resources from the database.
After the contractor has his resources and builds his model, he then uses it to construct the look of the house. In that same way, the Rails controller takes the model that is created with the resources and uses it to create the view of your webpage.
Without the framework and without Rails, it would be like building a house with no plans. Simply taking wood and saying, “Hey, I’m going to build something!” Now that would be complicated, and like so, working without Rails is similarly complicated. Rails creates the plans for you and streamlines your work so you can be twice as productive.
Now the metaphor is a bit more simplified than what really is going on. In reality, the process is much more involved, but that’s a topic for a later post.
Hopefully, you were able to follow along with my metaphor and have a better understanding of what Ruby on Rails is. As I continue on my journey into Code Fellows, I plan to post more and more topics about working with Rails. If you have any questions or topics that you’re interested learning about, please leave me a comment.