Category Archives: Ruby on Rails

Exploring Ruby on Rails (1) Install

I’m playing with Ruby. As a dynamic language, it is one of the programming languages to explore. I like plain Ruby, and write small programs using TDD (see my video in Anglish Playing with Ruby).

Now, I want to explore Ruby on Rails. It’s not in my comfort zone, because I think it is a “big project”, now in version 4.0. But it could be interesting to see how easy or convoluted could be to program using Rails, and to study the internal implementation.

So, in my Windows machine, some weeks ago, I installed Rails 4.x, using


gem install rails --no-rdoc --no-ri

I added –no-rdoc, –no-ri to skip the generation of local documentation.

It was a long output, see the gems that were installed:

Fetching: i18n-0.6.5.gem (100%)
Fetching: tzinfo-0.3.37.gem (100%)
Fetching: minitest-4.7.5.gem (100%)
Fetching: atomic-1.1.14.gem (100%)
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Fetching: thread_safe-0.1.3.gem (100%)
Fetching: activesupport-4.0.0.gem (100%)
Fetching: builder-3.1.4.gem (100%)
Fetching: actionpack-4.0.0.gem (100%)
Fetching: activemodel-4.0.0.gem (100%)
Fetching: arel-4.0.0.gem (100%)
Fetching: activerecord-deprecated_finders-1.0.3.gem (100%)
Fetching: activerecord-4.0.0.gem (100%)
Fetching: mail-2.5.4.gem (100%)
Fetching: actionmailer-4.0.0.gem (100%)
Fetching: thor-0.18.1.gem (100%)
Fetching: railties-4.0.0.gem (100%)
Fetching: bundler-1.3.5.gem (100%)
Fetching: sprockets-2.10.0.gem (100%)
Fetching: sprockets-rails-2.0.0.gem (100%)
Fetching: rails-4.0.0.gem (100%)
Successfully installed i18n-0.6.5
Successfully installed tzinfo-0.3.37
Successfully installed minitest-4.7.5
Successfully installed atomic-1.1.14
Successfully installed thread_safe-0.1.3
Successfully installed activesupport-4.0.0
Successfully installed builder-3.1.4
Successfully installed actionpack-4.0.0
Successfully installed activemodel-4.0.0
Successfully installed arel-4.0.0
Successfully installed activerecord-deprecated_finders-1.0.3
Successfully installed activerecord-4.0.0
Successfully installed mail-2.5.4
Successfully installed actionmailer-4.0.0
Successfully installed thor-0.18.1
Successfully installed railties-4.0.0
Successfully installed bundler-1.3.5
Successfully installed sprockets-2.10.0
Successfully installed sprockets-rails-2.0.0
Successfully installed rails-4.0.0
20 gems installed

It is interesting to note there were native extensions, something to explore.

Now, the rails command is in my path. How the install program added the command? Simply. If you have Ruby in your path, you have the bin folder in that list of directories. In my case, c:\Ruby193\bin. Every gem that has global commands, can put in that folder new files. In my case, rails, and rails.bat.

This is the content of the .bat file:

IF NOT "%~f0" == "~f0" GOTO :WinNT
@"ruby.exe" "C:/Ruby193/bin/rails" %1 %2 %3 %4 %5 %6 %7 %8 %9
@"ruby.exe" "%~dpn0" %*

It detects if it can use or not a ‘cmd trick’, see

It launch the ‘rails’ file in the same bin directory, using ruby.exe. The rails file has:

# This file was generated by RubyGems.
# The application 'railties' is installed as part of a gem, and
# this file is here to facilitate running it.

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1

gem 'railties', version
load Gem.bin_path('railties', 'rails', version)

It use rubygems, the Ruby packaging system, see:

It imports, not directly rails, but railties, using the gem method.

The Gem.bin_path returns the path for ‘railties’, see

In my case, the bin-path returns ‘c:\Ruby193\lib\ruby\gems\1.9.1\railties-4.0.0\bin\rails’. The second parameter ‘rails’ indicates the script to run. It is executed using the ‘load’ command:

load(filename, wrap=false) ? true

Loads and executes the Ruby program in the file filename. If the filename does not resolve to an absolute path, the file is searched for in the library directories listed in $:. If the optional wrap parameter is true, the loaded script will be executed under an anonymous module, protecting the calling program’s global namespace. In no circumstance will any local variables in the loaded file be propagated to the loading environment.

I should study the difference with ‘require’:

require(name) ? true or false

Loads the given name, returning true if successful and false if the feature is already loaded.

If the filename does not resolve to an absolute path, it will be searched for in the directories listed in $LOAD_PATH ($:).

If the filename has the extension “.rb”, it is loaded as a source file; if the extension is “.so”, “.o”, or “.dll”, or the default shared library extension on the current platform, Ruby loads the shared library as a Ruby extension. Otherwise, Ruby tries adding “.rb”, “.so”, and so on to the name until found. If the file named cannot be found, a LoadError will be raised.

For Ruby extensions the filename given may use any shared library extension. For example, on Linux the socket extension is “” and require ‘socket.dll’ will load the socket extension.

The absolute path of the loaded file is added to $LOADED_FEATURES ($"). A file will not be loaded again if its path already appears in $". For example, require ‘a’; require ‘./a’ will not load a.rb again.

require "my-library.rb"

require "db-driver"

Any constants or globals within the loaded source file will be available in the calling program’s global namespace. However, local variables will not be propagated to the loading environment.

That ‘rails’ file contains:

#!/usr/bin/env ruby

git_path = File.join(File.expand_path('../../..', __FILE__), '.git')

if File.exists?(git_path)
  railties_path = File.expand_path('../../lib', __FILE__)
require "rails/cli"

Apparently, the gem loader alters the require path, and the require of ‘rails/cli’ is resolved to ‘c:\Ruby193\lib\ruby\gems\1.9.1\railties-4.0.0\lib\rails’.

Ok, enough for today. Next steps: explore the load of rails, parameters, and create a site.

Keep tuned!

Angel "Java" Lopez

Ruby On Rails (2): Links, News and resources

Previous Post

More links about this popular Ruby web framework (and some discussions):

Crazy, Heretical, and Awesome: The Way I Write Rails Apps

Rails Went Off The Rails: Why I’m Rebuilding Archaeopteryx In CoffeeScript

Frontend Code Doesn’t Have to Suck: 5 Tips for Rails Developers

Moving from Sinatra to Rails

ruby-debug in 30 seconds (we don’t need no stinkin’ GUI!)

What programming language is GitHub written in?

Rails: Presenter Pattern

Ruby/Sinatra/Rails failing at Start

Sinatra vs. Rails

Rails Caching Benchmarked: MongoDB, Redis, Memcached

Lately there has been a lot posts about how Ruby on Rails might not follow the best practices.

ActiveRecord (and Rails) Considered Harmful

Composition Of Responsibility vs Interface Implementation
ActiveRecord might truly be a horrible beast with far too many concerns in one given place. I haven’t dug into that source code very much. From what I remember of it, it’s huge and difficult for me to understand (but then, it does a metric-ton-squared of meta-programming, so I guess I’m not surprised that it’s hard for me to understand).

Rails Has Turned Me Into a Cannibalizing Idiot
Some interesting posts flying around about how ActiveRecord is rotting people’s brains and how Rails is "pants on head retarded". I figured I might as well respond.

spree / spree
Spree is a complete open source e-commerce solution for Ruby on Rails

Is it better to use routes or mod_rewrite to forward old URLs?

How to make Rails do not ignore trailing slashes in the routes?

SEO, Heroku, Ruby on Rails and removing those darn trailing slashes

El maldito libro de los descarrilados
Tutorial de Ruby on Rails en castellano

Using Redis with Ruby on Rails

To Redis or Not To Redis? (Key-Value Stores Part 4)

Delivering email with Amazon SES in a Rails 3 app

Activity Logs and Friend Feeds on Rails & pfeed

Ruby On Rails español

Entrenando con Ruby y RoR

Learning how to Learn Rails

nicksieger / refactoring-to-rails
Example of refactoring a Spring/Hibernate application to Rails

Configuration for Rails, the Right Way

Ruby clouds: Engine Yard vs. Heroku

Memcached Internals: Memory Allocation, Eviction Policy, Consistent Hashing

Heroku and Rails 3.1

Ruby on Rails 3.0 Release Notes

Instalar Ruby on Rails 3 en Windows

Rails QRCode Generator

How do I add a field in Ruby on Rails?

Why Bother With Cucumber Testing?

Mini reviews of 19 Ruby template engines

Ruby on Rails Tutorial

Rails Searchable API Doc

Bundler manages an application’s dependencies through its entire life across many machines systematically and repeatably.

Getting Started with Rails

Updating Ruby / Rails

My Links

More links about Ruby, Ruby web development, Sinatra, etc… are coming.

Keep tuned!

Angel “Java” Lopez

Ruby on Rails, Demo Application (1) Creating the Application

I wrote a post series about my experience at the past Ruby Fun Day at Buenos Aires, in Spanish:

Mi Día en el Ruby Fun Day with @bendycode

Now, I want to write my learning steps following the chapter 2 of Michael Hartl book Ruby on Rails 3 Tutorial: Learn from Example.

I installed Ruby on my Windows box, using (more options at In Windows, you should install DevKit (a minimalist GNU for windows (mingw)). See Ruby Installer page for link download. The instructions to install it are at (some details in Spanish).

Then, I executed the command (at any command prompt)

gem install rails

that installs Ruby on Rails, a web framework for Ruby. Go to a working directory (in my case c:\Git), and execute



Then I executed

rails new RailsDemoApp

with output:

Change to the new directory:

cd RailsDemoApp

Now, you have a folder tree like:

Ruby manages gems (package to install and use). Rails itself is a gem. And Rails application have a GemFile that list the gems our new application will use. Just in case we have a new gem to install, execute:

bundle install

Bundle is the new package installer used in Ruby on Rails 3. It reads the GemFile and installs (in Ruby gem directory, in our machine, it’s not per application) the needed gems. Then, you can execute:

bundle show

I configured the current directory (Git\RailsDemoApp) to be a Git repo:

git init
git add .
git commit –m “Initial Commit”

I added a new repository in my GitHub Account using

The new repo:

I added and pushed to the remote repo:

git remote add origin
git push origin master

You can launch the initial server with

rails server

or its shortcut

rails s

See the result at http://localhost:3000

Next steps: adding a simple model (users, micropost), database, views, controllers, scaffolding, and Heroku deploy. Scaffolding (quick CRUD code generation) will be the approach to use in this series, but in a following post series I want to show (and learn 😉 the making of a Rails application, step by step, as in Hartl book.

Keep tuned!

Angel “Java” Lopez

Ruby On Rails: Links, News and Resources (1)

Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.

Ruby on Rails was extracted by David Heinemeier Hansson from his work on Basecamp, a project management tool by 37signals (now a web application company).[9] Hansson first released Ruby on Rails as open source in July 2004, but did not share commit rights to the project until February 2005.[10] In August 2006 the framework reached a milestone when Apple announced that it would ship Ruby on Rails with Mac OS X v10.5 “Leopard”,[11] which was released in October 2007.

Ruby on Rails version 2.3 was released on March 15, 2009. Major new developments in Ruby on Rails include templates, engines, Rack and nested model forms. Templates enable the developer to generate a skeleton application with custom gems and configurations. Engines let one reuse application pieces complete with routes, view paths and models. The Rack web server interface and Metal allow one to write optimized pieces of code that route around ActionController.[12]

On December 23, 2008, Merb, another web application framework was launched, and Ruby on Rails announced a commitment to work together. The Ruby on Rails team announced they would work with the Merb project to bring “the best ideas of Merb” into Ruby on Rails 3, ending the “unnecessary duplication” across both communities.[13] Merb was merged with Rails as part of the Rails 3.0 release.[14][15]

Jumpstart your Ruby on Rails 3 applications with rails-templater

Rails Wizard

Why DataMapper?

Crafting Rails Applications: Why I wrote this book

Rails Routing from the Outside In

Crafting Rails Applications: Expert Practices for Everyday Rails Development

Why Rack should matter to .NET developers

Rack is a layer of abstraction which sits between servers and frameworks. What it brings as a result is greater interoperability between HTTP server implementations and web frameworks. As the author of a HTTP server if you get your server to speak Rack you can now host applications written in several Ruby frameworks, Sinatra and Rails being two of the most well known.

VAN – Noviembre 20 de 2010 – Ruby on Rails

By @mario_chavez

Ruby on Rails Tutorial: Learn Rails by Example

Rails for Zombies

Alberto Perdomo Presentations

Rails101 Tutorial Ruby on Rails with Relations

Nimble Method

Rails 3 Screencasts

Helicon Zoo — a repository of web frameworks and applications for Microsoft IIS.

It supports Rails

Rails en la nube se llama Heroku!/2011/10/rails-tiene-scaffold-nosotros-usamos.html

Ubuntu 11.10 to support the Cloud Foundry Platform-as-a-Service

From .NET to Ruby: Adventure, Courage, and Joy

Why ruby?

La complejidad de Ruby On Rails

A Guide To Starting Your Own Rails Engine Gem

Java Developers have Loads to Learn from the Rails Community

Ruby Version Manager (RVM)

ALT.NET Café – Mayo 13 de 2011 – La Inmortalidad de la Medusa – Web Frameworks

Advanced Data Models with Rails

Rails Best Practices

Easy Rails OAuth Integration Testing

Rails 3 Baby Steps – Part 2

Radiant / radiant

Radiant is a no-fluff, open source content management system designed for small teams. It is similar to Textpattern or MovableType, but is a general purpose content management system (not just a blogging engine).

RESTify DayTrader

[RAILS 101] Video Tutorials Ruby On Rails

Rails Installer (for Windows)

Ruby and Rails for Attractive .NET Developers

kfaustino / rails-templater

Template generator for Ruby on Rails 3 applications

Ruby on Rails Tutorial

Development Kit: How to install it

Rails Searchable API Doc


Bundler manages an application’s dependencies through its entire life across many machines systematically and repeatably.

Getting Started with Rails

My links

Keep tuned!

Angel “Java” Lopez