- Rails Intro, Deep Dive: RVM
- Rails Intro, Deep Dive: Installing Rails, Part One
- Loccasions: Installing Rails Part 2
- Rails Intro, Deep Dive: App Generation
- Rails Deep Dive: Application Setup, Loccasions
- Rails Deep Dive: Loccasions, Home Page
- Rails Deep Dive: Loccasions, Authentication
- Rails Deep Dive: Loccasions, Spork, Events and Authorization
- Rails Deep Dive: Loccasions, Making Events
- Loccasions: Pair Programming
- Loccasions: Hiring a Foreman, Inheriting Resources, & Occasions
- Loccasions: Going Client-Side with Leaflet, Backbone, and Jasmine
- Loccasions: Getting to Occasions
- Loccasions: Bubbly Map Events
- Loccasions: Retrospective
Continuing from my last post about RVM, this time we’ll install Rails. Again, this series attempts to give you a bit of a deeper dive into getting started with Rails, so we will go through some of the options available when first creating your world-changing Rails application, as well as the gems that are installed along with Rails.
Selecting the Interpreter
First things first, make sure you open up a terminal and switch to our RVM Ruby interpreter and gemset, which is MRI 1.9.2 and rubysource, respectively. We do that with
and you can verify with a quick
rvm info. As you probably know, the way to generate a new Rails application is by typing this at the command prompt.
rails new applicationName
What you may not know is where Rails executable lives. In fact, it may surprise you to know that the only thing the Rails gem includes is the rails executable. The Rails gem has many dependencies, which are satisfied by other gems, but the actual Rails gem is just an executable. Let’s install it now.
gem install rails --pre
--pre option tells RubyGems to install the latest available gem, which may not be the “official” stable version of Rails. In our case, we get Rails 3.1 RC4. “RC4″ stands for Release Candidate 4, which should be the last of the release candidates before Rails goes stable, which is another way to say it is released. We can see the general release cycle that Rails follows by looking at the tags on Github
Where we can see that Rails follows a pattern of starting with a “beta” release, followed by 4 or 5 release candidates, before going stable. Thanks to RVM, we can muck about with any of the pre-release software without contaminating the rest of our development environment.
Now you know what the “–pre” option does when installing the Rails gem, but what other options are there? “gem install” takes many options, which we can see here.
RubyGems allows us to specify items, such as, a specific version (which we’ve seen), an install destination, whether or not to install documentation, whether or not to install dependencies, as well as specifying a source for searching for gems. Looking over the available options, it’s easy to see how RVM leverages RubyGems to keep gemsets isolated. Finally, you can put any of these options into your ~/.gemrc file if you find yourself typing the same options over and over again. As a special bonus, here is a way to significantly speed up your gem installs by setting options in your Gem configuration file.
Other Gems Installed
When we installed Rails, it also installed several other gems. What are those gems? What is their purpose?
Let’s briefly run through each one.
MultiJSON (by Intridea, who do great stuff) allows for multiple JSON backends, detecting and leveraging the best one. In the case of the vanilla Rails install, it uses the
ActiveSupport is “a collection of various utility classes and standard library extensions that were found useful for Rails. All these additions have hence been collected in this bundle as way to gather all that sugar that makes Ruby sweeter.” This means, in essense, that ActiveSupport is THE building blocks of Rails, including abstractions for caching, JSON support, unicode support, and notifications. It also defines ActiveSupport::Railtie, which is one of the ways to extend your Rails application. The breadth of ActiveSupport is far too large to cover here, so check it out in your spare time.
Builder provides a Domain Specific Language (DSL) for generating markup.
The i18n gem provides all the localization support for Rails. As you can imagine, this is a large topic, and one worth studying as you grow in your Rails knowledge.
ActiveModel provides the the interface for models in Rails. ActiveModel was provided starting in Rails 3.0, allowing the developer to go through the buffet line of the syntactic sugar provided to models in Rails and only put the desired bits on the plate.
The Rack Gems.
Rack provides the interface to the web server from Ruby applications. One of the items supported by Rack is middleware, allowing for bits of code to be dropped into the web request/response pipeline and provide functionality. rack-cache is middleware providing HTTP caching. rack-test provides an API for testing Rack apps (which is what Rails is) in the form of a nice DSL. rack-mount provides the routing for Rails, which drives the nice RESTful interface of a standard Rails application.
Hike handles the load and search paths for Rails.
Tilt provides an interface to different Ruby templating engines, like ERB and Haml.
TZInfo is a timezone library for Ruby.
Well, this post is reaching the point where it can’t be read on the train or waiting at the dentist, so I am going to split up the gem descriptions into two posts. We will pick up with the Erubis gem next time. I hope you are finding this approach to starting off with Rails educational and enlightening. As always, if you see anyway to improve the article or add insight, please leave a comment.