Skip to content

Latest commit

 

History

History
125 lines (76 loc) · 3.21 KB

README.rdoc

File metadata and controls

125 lines (76 loc) · 3.21 KB

LightScaffold

For those who want the old dynamic scaffold with the power of customization.

Installing

Install it:

$ ruby script/plugin install git://github.com/lucasdecastro/light_scaffold.git

Install inherit_views plugin:

$ ruby script/plugin install git://github.com/ianwhite/inherit_views.git

Install your preferred base controller like inherited_resources [github.com/josevalim/inherited_resources] or resource_controller [github.com/jamesgolick/resource_controller].

$ ruby script/plugin install git://github.com/josevalim/inherited_resources.git

Usage

Controllers

Create a controller with the default actions and views:

class ScaffoldController < InheritedResources::Base
  inherit_views
end

Create your controller inheriting from ScaffoldController.

class PagesController < ScaffoldController
end

Views

When you install the plugin, a directory called scaffold is created under app/views. It contains some views templates that will be used to render your scaffolds.

This views have same names of views generated by default scaffold: index, new, edit, _form and show.

Customizing templates for all the scaffolds

Just change templates included in app/views/scaffold.

Customizing templates for one scaffold

Just copy the desired template from app/views/scaffold to app/views/<resource_name>/ and change it.

$ cp app/views/scaffold/index.html.erb app/views/users/

Customizing some columns with helper methods

You also can define some methods in a helper to change how a column will be display. To do this, you need include LightScaffold::Helper.

module UsersHelper
  include LightScaffold::Helper
end

Choose which columns appear

module UsersHelper
  include LightScaffold::Helper

  def columns
    ['login', 'name']
  end

  def form_columns
    super + %(password password_confirmation)
  end
end

The columns method will affect all the views of UsersController. To affect a specific view use index_columns, form_columns or show_columns methods.

Shortcut:

module UsersHelper
  include LightScaffold::Helper

  columns :login, :name
  form_columns  :login, :password, :password_confirmation
end

Remember that the order of columns will be preserved as declared.

Choose how a column appear

The idea these helpers were hijacked from ActiveScaffold plugin.

module UsersHelper
  include LightScaffold::Helper

  def website_column(user)
    autolink user.website
  end

  def about_form_column(form, user)
    form.textarea 'about', :rows => 3
  end

  def level_id_form_column(form, user)
    form.select 'level_id', Level.all.collect {|l| [l.description, l.id ]}, { :include_blank => true })
  end
end

Shortcut:

module UsersHelper
  include LightScaffold::Helper

  password_field :password
  password_field :password_confirmation
  textarea       :about, :rows => 3
end

You can use this shortcut for all the methods of ActionView::Helpers::FormHelper, except form_for and fields_for.

Credits

This plugin is very simple. All the magic was done by other plugins. Thanks to inherit_views, inherited_resources and resource_controller.

Copyright © 2009 Lucas de Castro, released under the MIT license