If you were one of the unfortunate souls who missed RailsConf this year, I’m sorry for you. If you happened to be at RailsConf but missed Justin Gehtland’s excellent Streamlined tutorial then you are truly of all people most pitiable.

On a more serious note, the tutorial was very good and has sparked a lot of interesting ideas for further enhancing Streamlined beyond its already hefty feature set. For those who don’t know, Streamlined is a Rails plugin that brings the declarative goodness of ActiveRecord to the UI. It enhances your views with full-featured scaffolds that include relationship management, quick adding of associated models, and much more.

If you haven’t played with Streamlined before, why not give it a try? With several fresh screencasts over at the blog, a bundle of new documentation, a new sample project, and version 1.0 on the horizon… there’s no time like the present.

Getting started with Streamlined is easy…

First, let’s create a new Rails application and install the plugin:

$ rails address_book
$ cd address_book
$ script/plugin install http://svn.streamlinedframework.org/edge/streamlined/

Second, generate a controller and a model:

$ script/generate controller People
$ script/generate model Person

Third, make the controller Streamlined-enabled by adding this code to it:

class PeopleController < ApplicationController
  layout "streamlined"
  acts_as_streamlined
end

Streamlined will assume that our controller name matches the name of the model the controller manipulates. The above example automatically uses the Person model we created.

Now let's setup the fields for our Person model. Open the migration at db/migrate/001_create_people.rb and edit it to look like this:

class CreatePeople < ActiveRecord::Migration
  def self.up
    create_table :people do |t|
      t.column :first_name, :string
      t.column :last_name, :string
      t.column :email, :string
    end
  end

  def self.down
    drop_table :people
  end
end

Finally, let's start our server and open the application:

$ script/server
$ open http://localhost:3000/people

Note: If you're on Windows, the open command won't work. You'll need to open Internet Explorer or Firefox and navigate to localhost:3000/people manually.

You should see Streamlined's interface in your browser, along with an empty list of people. Click the plus icon to add a new person. Try clicking on a column to sort the list. You can also edit and view existing people in the list and filter the list using the text box on the top right of the page.

In my next post, we'll create a UI class to go along with our model. We'll begin adding declarations to the UI class to change the way Streamlined renders our data.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn