stephanie writes code

(For People Who Read English Good)


Rails in 15 Minutes

It’s been about 4 weeks since we began learning Rails, and two of those weeks we’ve spent in manic project mode. Manic in a good way, of course — as in everyone has been relentlessly devoted to building Rails-based web applications (which has also forced many of us to learn WAY more about AJAX and jQuery on the fly than we ever thought possible in such a short amount of time, especially in tandem with learning an entire framework from the ground up). I think what I’m hinting at is: major brain overload (or brain… overflow? sorry — terrible joke).

I take it for granted now that I occasionally have to battle my instance variables when using form_fors or forget to set before_actions. Because not too long ago, in a very serious way, I literally had no idea what Rails was.

Sure, I’d heard and read multiple times that Rails “is a framework for building web applications”. But what, then, was a framework? How did Ruby fit into it? Were Rails and Ruby on Rails the same thing? I had so many questions prior to these last 4 weeks, and though many had recommended Code School’s Rails for Zombies series, I just couldn’t get into it.

So hopefully, the following breakdown is helpful to anyone who’s just embarking upon their soon-to-be awesome journey into Rails:


Okay, so what is Rails?

Rails is a framework for building web applications.

Just kidding.

Well, that’s actually true, but I’m going to attempt a better explanation because that one is vague and unhelpful. To begin, I’d like to share a few broad (as in, not specific to code or programming) definitions of the word ‘framework’ that I think best apply to the context of Rails:

framework [ˈfreɪmˌwɜːk] n

  1. A skeletal structure designed to support or enclose something else
  2. A set of concepts, assumptions, values, and practices that constitutes a way of viewing reality

Okay, now keep those definitions on a mental back-burner. Because they apply to Rails in the sense that they help add brushstrokes and color to the overall picture, but neither of those definitions alone is entirely helpful in grasping — at the most basic level — what Rails IS.

As simply and literally put as possible, Rails is a kind of software, or ‘magic kit’, that you download locally on your computer via one simple command in your terminal (assuming you already have the RubyGems packaging system): gem install rails. Once you’ve installed it, Rails provides you with a whole bunch of functionality so that you can efficiently start building web applications. In other words, there’s a vast library behind the scenes (i.e the Rails source code) into which a lot of complex methods and logic have been defined and pre-coded by some really smart people (like this guy) so that you don’t have to; instead, you can type some simple commands like rails new [project name] or rails generate scaffold [model], and Rails will respond to them.


Now, how exactly is Rails like a ‘framework’?

To relate this back to the above definitions, rails is a framework in the sense that its many built-in shortcuts will magically create skeletal structures (organized directories, basic routes, empty models with their corresponding migrations, etc.) for you to fill in with further details, i.e code and logic. It also encapsulates its creator(s)‘ values, assumptions, and opinions on programming best-practices, i.e THEIR way of viewing ‘reality’.

One of the most definitive illustrations of how ‘framework-like’ Rails is is the directory structure you instantly get after running rails new [project name]. Something like 30 directories come pre-organized, nested and labeled for you — and some even contain files with pre-written CODE! Thus, rather than leave it up to each individual programmer to organize his or her directories in whatever way he/she deemed fit, the masterminds behind Rails decided to take choice out of the equation and hammer home instead a pre-determined layout to encourage convention. Their values and assumptions are clearly at play here. And though it may sound stiff and undemocratic at first, once you use Rails to build stuff (and conversely, have to jump into other people’s Rails projects — oftentimes to debug), you’ll realize how time-saving and mental energy-saving these baked-in conventions truly are. So thank you, DHH, for having an opinion!


So you can build real web apps in fewer than 5 lines of code??

Well, sort of. Five lines of code will get you some basic CRUD functionality, but that’s about it.

Unfortunately, while Rails’ out-of-the-box mileage is great, it isn’t really going to cut it when you have to build anything for real. That is, any serious web application you build using Rails is going to require a lot of customization, i.e you’re going to need to read quite a bit of Rails documentation and learn how it’s really used — and knowing the Ruby language will really help here.

A lot of well-known sites and applications do use Rails, including some you may have heard of: Shopify, Twitter, Github, and more.

Exicted to start Rails-ing, much?

(If the answer is ‘YES!’, then I suggest starting here, with Michael Hartl’s free Rails tutorial. It’s super step-by-step, controlled, and well-explained every step of the way. He also ties in some Git and Heroku, which is a nice touch because it helps contextualize all the other stuff you’ll actually come in contact with when you use Rails for real. And personally, I say skip the Rails guide for now until you’ve had some practice going through the motions, a la Hartl’s tutorial. Otherwise, you’ll have no context. Besides, guides are best used in general for “sandboxed queries” — once you have an idea of something specific you need an answer to).


Are ‘Rails’ and ‘Ruby on Rails’ the same thing?

Yes.

Rails is simply the shorthand version of saying it; Ruby on Rails is the same thing.


How does Ruby fit into it?

Rails/Ruby on Rails was built using the Ruby programming language, and thus also runs on Ruby. That’s a pretty direct way in which Ruby ‘fits into the picture’. And as mentioned above, any customization and/or granular manipulation of your Rails-based web application is going to require some real knowledge of Ruby; you don’t need to be an expert, but much of what you want to accomplish and much of the control over what data you choose to display (or not display) is going to rely on basic Ruby stuff like the .each method, if else logic, etc.

(If you want recommendations on free beginner Ruby resources, I personally like Codecademy, RubyMonk, and Chris Pine’s Learn to Program.)


I think that was approximately 15 minutes’ worth of reading?

Happy Rails-ing!