developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Shop
Memory Upgrades
Cell Phones
Web Hosting Directory
Disney World Tickets
Phone Cards
KVM Switches
Promos and Premiums
Laptops
Imprinted Gifts
Find Software
KVM over IP
Home Improvement
Televisions

 
Biz Resources
Data Integration Software
Web Hosting
Email Solutions


Download these IBM resources today!
e-Kit: IBM Rational Systems Development Solution
With systems teams under so much pressure to develop products faster, reduce production costs, and react to changing business needs quickly, communication and collaboration seem to get lost. Now, theres a way to improve product quality and communication.

Webcast: Asset Reuse Strategies for Success--Innovate Don't Duplicate!
Searching for, identifying, updating, using and deploying software assets can be a difficult challenge.

eKit: Rational Build Forge Express
Access valuable resources to help you increase staff productivity, compress development cycles and deliver better software, fast.

Download: IBM Data Studio v1.1
Effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life.

eKit: Rational Asset Manager
Learn how to do more with your reusable assets, learn how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse.
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Project Management Guide: Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.

Rails 2: The Top Five Features List
By Jason Gilmore

Go to page: 1  2  Next  

It's the start of the new year, and as usual the media is trotting out their annual "lists" for 2007 ad nauseum. Best sports moments, worst political gaffes, sexiest celebrities... you name the topic and somebody's come up with a list itemizing its relevance in 2007. I thought I'd pen my first Developer.com column of the year in similar fashion, highlighting my personal take on top five features of the new Rails 2 release. Keep in mind this isn't a comprehensive breakdown, nor is it a summary of the most complicated new features, but rather it's an overview of a few key new features which are already making me a more productive developer. And that's ultimately the point of Rails, isn't it?

Feature #1: Even Easier View Management

In an effort to stay DRY (Don't Repeat Yourself), Rails developers often use partials to maintain a single data format that can be invoked from within numerous controller methods. For instance, consider the following controller, which might be used to retrieve URLs from a database:

class LinksController < ApplicationController
   def index
      @links = Link.find(:all)
   end

   def show
      @link = Link.find(params[:id])
   end
   ...
end

A single partial would be used for both the index and show methods. It might look like this:

<p><%= link_to h(link.name), link.url %></p>

Finally, the respective views would look like this:

# index view

<%= render :partial => 'link', :collection => @links %>

# show view

<h3><%= @link.name %></h3>

<%= render :partial => 'link', :object => @link %>

Rails 2 allows you to create even more succinct view code when referencing partials. Running Rails 2, the following views can be rewritten like so:

# index view

<%= render :partial => @links %>

# show view

<h3><%= @link.name %></h3>

<%= render :partial => @link %>

Feature #2: Very Easy Authentication

I've used the Restful Authentication plugin on several Rails projects, and find it to be an incredibly intuitive and easy way to manage all aspects of user authentication, including registering, logging in to, and out of the application. But perhaps it's overkill if you're simply looking for an easy way to password protect a page. Rails 2 resolves this dilemma by introducing a basic HTTP authentication feature. To use it, you create a before_filter within the controller you'd like to protect, and within the filter method use authenticate_or_request_with_http_basic, like so:

class AdminController < ApplicationController
   before_filter :authenticate

   protected
   def authenticate
      authenticate_or_request_with_http_basic do |username,
      password| username == 'jason' && password == 'supersecret'
   end
   ...
end

When the user attempts to access any resource found under the Admin controller, he'll be greeted with the familiar authentication prompt. Entering a username of jason and a password of supersecret will grant him access; otherwise, he'll be prompted anew.

Of course, hardcoding a username and password into the method isn't exactly practical. Instead, you can invoke a method that will check against the database for a matching login pair.

Feature #3: Condensed Migrations Syntax

Migrations is far-and-away one of my favorite features of the Rails framework. In fact, I've written extensively about the topic in recent articles published here on Developer.com (See "Raking MySQL Over Rails" and "Manage Your MySQL Database with Rails' Migrations"). Indeed, the ability to manage your database schemas using a distinctly programmatic approach is truly compelling to developers like myself who prefer to keep database-related tasks at arms' length.

Evolving a schema programmatically is indeed appealing, but even Migrations syntax can become a bit tedious over the course of an application's lifetime. For instance, I recently created a migration for a new table; it looked like this:

class CreateUsers < ActiveRecord::Migration
   def self.up
      create_table :users do |t|
         t.column :name, :string
         t.column :email, :string
         t.column :bio, :text
         t.column :created_at, :datetime
         t.column :updated_at, :datetime
      end
   end

   def self.down
      drop_table :chapter_comments
   end
end

Go to page: 1  2  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Web Services Archives

Generate Complete .NET Web Apps in Minutes . Download Iron Speed Designer today.
Is it time to make your move to the multi-threaded and parallel processing world? Find out!
Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.
Intel Go Parallel Portal: Translating Multicore Power into Application Performance
Data Sheet: IBM Information Server Blade



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES