Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

A Flickr-based Introduction to Ruby on Rails 2.0 : Page 2

Want to get started with Rails 2.0? Explore some of the most prominent new features, and learn how to use them to build a simple, but visually attractive, web application based on Flickr.


advertisement
Installation and Basic Setup
The first thing you have to do is install the Rails 2.0 framework and create a basic application scaffold to verify that everything has been setup properly. If the Ruby language and RubyGems, the standard packaging system for Ruby libraries, are not already installed on your system, refer to the Ruby and RubyGems web sites for further installation information. Also, check out Pastie, a tool that checks if your applications based on Rails 1.x are ready to be migrated to the new version.

Once you have these ready to go, you can install Rails 2.0 using the same procedure as for the previous version of the framework. Then open a terminal and enter this command:

gem install rails --include-dependencies



You can also launch the gem command with explicit references to the required libraries and verify that it downloads the correct packages from the Internet:

$ sudo gem update actionmailer actionpack activerecord activesupport $ sudo gem install activeresource $ sudo gem update rails $ ruby -v ruby 1.8.6 (2007-09-24 patchlevel 111) [universal-darwin9.0] $ gem -v 1.0.1 $ rails -v Rails 2.0.2 $ gem list --local *** LOCAL GEMS *** actionmailer (2.0.2, 1.3.6, 1.3.3) actionpack (2.0.2, 1.13.6, 1.13.3) actionwebservice (1.2.6, 1.2.3) activerecord (2.0.2, 1.15.6, 1.15.3) activeresource (2.0.2) activesupport (2.0.2, 1.4.4, 1.4.2) rails (2.0.2, 1.2.6, 1.2.3) ... other libraries here ...

As you can see, you can keep the previous version of Rails alongside with the new one, to facilitate the transition of existing applications built upon previous Rails versions. The above example has both Rails 2.0.2 and two previous versions of Rails 1.2. (The Ruby on Rails download page describes additional ways of installing it.)

To verify that everything is working correctly, you can generate a scaffold for a new web application with this command:

rails testapp cd testapp/ script/server

Open your browser at the URL http://localhost:3000 to verify that you are using the latest version of Rails. You should see a welcome screen for your newly created Rails 2.0 application like the one shown in Figure 5. If you don't, check the RAILS_GEM_VERSION in the testapp/config/environment.rb file.

 
Figure 5. The Welcome Screen of a Newly Created Rails 2.0 Application.

The RailTrackr Application
RailTrackr, the visually rich, web-based Flickr photo browser, will demonstrate some notable Rails 2.0 capabilities. You can launch the sample application now by downloading the source code attached to this article and launching it with the traditional script/server command. Since the application uses the Flickr APIs to load photos, you have to request an API key from the Flickr services site and type it into the flickr_helper.rb file bundled with the source code.

The application provides a way to navigate through Flickr users, their photosets, and the photos contained within them. It therefore defines three entities: FlickrUser, Photoset, and Photo. In the application domain, a FlickrUser may have many Photosets, and each Photoset may have many Photos. These will be the Ruby models for RailTrackr.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date