September 2, 2008

Rails Is Not A Language

Filed under: classes, gems, rails, ruby — oomoo @ 2:02 pm

Say it with me… “Rails Is Not A Programming Language”.  Thanks!  It’s easy to forget sometimes that all the magic of Rails is actually riding on a foundation of Ruby.  Rails is a “Web Application Framework” that is written in Ruby.  Ruby actually IS a programming language, Rails is a set of  classes/packages designed to do a lot of the tedious work typically involved in writing a web-based application. 

Ruby is very extensible, owing much to the fact that it is basically compiled on-the-fly.  This means that Ruby can pull in chunks of code as needed and integrate them as new functionality or to augment/override even base functionality.  Usually, these additional pieces of functionality are in the form of “Gems” (get it… Ruby… Gems).  Well, Rails itself is actually just another Ruby Gem (technically a collection of Gems)!  You install Rails (and update it going forward) using the same Ruby commands you would use to install any other Ruby add-on.  I suppose that Rails seems like a language because it actually becomes your interface to Ruby, wrapping Ruby “the language” inside of itself.

The idea behind Rails is to abstract complexity whenever possible, integrate existing 3rd part tools whenever practical, and provide structure, intuitiveness, and design simplicity wherever probable.  Installation of Rails automatically includes the base packages (ActiveRecord, ActionController, ActionView, etc.), a back-end ruby web server called WEBrick, and the JavaScript libraries “Prototype” and “Script.aculo.us” to do the pretty AJAX stuff in the browser.  So, with all of these typically independent pieces neatly wrapped up into one integrated package, it is easy to see why so many people initially mistake Rails for a programming language.


The Rails framework does a great job of things like:

  • Giving you the feel of working in an integrated environment.  It does much of this by replacing traditional HTML-only files with a pseudo-HTML file into which you can combine Rails objects and variables and Rails method calls directly (in-line) with your HTML, CSS, and JavaScript.
  • Integration of JavaScript (Prototype and Script.aculo.us) into Rails helper methods hiding some of it’s complexity
  • Taking care of routing web requests
  • Creating secure communication sessions
  • Generating e-mail
  • Ability to generically output to many formats (XML, HTML, etc.) with almost no additional coding
  • Automatic integration of a testing environment for unit and application regression tests


Where it really shines is helping you create database applications, since it will help you do things like:

  • Handle database transactions
  • Performing data validation
  • Automatically show/update related records
  • Record locking/detection of stale data
  • Generating automated testing routines
  • Performing SQL without writing pages full of SQL
  • Maintain the state/values of variables and objects between your web pages and your code
  • Performing database record caching inside easy-to-use memory objects. 


Rails “encourages” (almost demands) standardized folder structures, file naming, and method naming conventions.  This may feel limiting to some at first, but the payoff is extraordinary.  It infers a level of self-documentation to every project.  It makes it much easier for new developers to join a development team at any stage. It also makes technical documentation and blogs such as this one easier to write because so many things can simply be assumed about the development environment.

The naming standards, request routing, and other basic concepts in Rails afford you some additional cool abilities when it comes time to move/change your application/server/database:

  • instantly move your applications between development, test, and production
  • duplicate/rename an entire application without making any code changes
  • change your back-end database “from” just about any database technology “to” just about any database technology with no code changes
  • change your server-side


In Summary…

  • Rails is not a language
  • Ruby is a language
  • “Ruby on Rails” is the official name 
  • “Rails on Ruby” would probably be a more accurate description, but it just doesn’t roll off the tongue as well or sound quite as sexy.

Can you write a Ruby on Rails application without learning Ruby?  It is a testament to the depth of the Rails framework that you actually could write any number of fairly simple web applications without learning a tiddle of Ruby.   You obviously are still “using” Ruby, even if you don’t really understand it.  Doing this, however, would not be a very wise undertaking.  It would be like planting your very first garden without knowing the first thing about dirt, water, sunlight, or (dare I say it) bugs.


Wanna try Rails?

Have a Mac?  Rails is built in, see my post:  Is Mac Perfect for Rails Development

Getting Started?  See my post:  Getting Started Tips

Try Ruby without the Rails (in your browser):  Try Ruby

If you want to see some other web frameworks, look here: Wikipedia – List of Web Application Frameworks

August 19, 2008

Update Rails/Rake/Gems

Filed under: gems, rails, rake — oomoo @ 9:09 am

Keep your Rails/Rake/Gems up-to-date by running these commands:

Update the RubyGems system itself (required by Rails 2.0).
gem update –system

Update Rails-specific gems and installs any new components (specifically Active Resource).
gem install rails

Update Rake, the build tool used by Rails.
gem update rake

Update the Ruby bindings for the SQLite3 database.
gem update sqlite3-ruby

For an existing project, also do this:

rake rails:update

…and edit the config/environment.rb file and set the correct GEM Version:

RAILS_GEM_VERSION = ‘2.1.0’ unless defined? RAILS_GEM_VERSION

You might want to make sure your migrations are up-to-date:

rake db:migrate
rake db:schema:dump


Check your GEM version:
gem –version


Downgrade/Rollback GEM
gem -v


List all the installed gems by typing:

gem list


View the documentation for all the installed gems by typing:

gem server

To access the documentation, point your browser to http://localhost:8808/

This command starts a web server on port 8808 by default. 

You’ll see a list of the gems you have installed with a link to their RDoc documentation.


Install SQLite3:
gem install sqlite3-ruby


Force Rails to use MySQL (instead of the default SQLite3):

rails -d mysql myapp


Create a free website or blog at WordPress.com.