-
Notifications
You must be signed in to change notification settings - Fork 332
Getting Started
For rails 2.3.x rails use the first command (or second one if you need backwards compatibility), rails version 2.2 use the third command and rails 2.1 use the 4th command.
anything prior use the fourth command
./script/plugin install git://github.com/activescaffold/active_scaffold.git
./script/plugin install git://github.com/activescaffold/active_scaffold.git -r rails-2.3
./script/plugin install git://github.com/activescaffold/active_scaffold.git -r rails-2.2
./script/plugin install git://github.com/activescaffold/active_scaffold.git -r rails-2.1
./script/plugin install git://github.com/activescaffold/active_scaffold.git -r 1-1-stable
Rails 2.3.x needs the plugin render_component for nested scaffolds
./script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3
Rails 3.x – ActiveScaffold currently does not currently work with Rails 3
Use script/generate resource
and create the layout by yourself, or use script/generate scaffold
and remove generated controller code and the views.
Add this inside your layout:
<%= javascript_include_tag :defaults %>
<%= active_scaffold_includes %>
Add this inside the controller you want to run the scaffold:
active_scaffold :<your_model_name>
Add :active_scaffold => true to your routes.rb file:
map.resources :<your_model_name>, :active_scaffold => true
Let’s say you want to scaffold Companies. You might create a layouts file in app/views/layouts/companies.html.erb that looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Generic ActiveScaffold Layout</title>
<%= javascript_include_tag :defaults %>
<%= active_scaffold_includes %>
</head>
<body>
<%= yield %>
</body>
</html>
And then you might create a CompaniesController that looks like this:
class CompaniesController < ApplicationController
active_scaffold :company
end
Your scaffold should be up and running with default everything right now. Not quite how you want it?
First let’s introduce the global config block. You probably noticed that the active_scaffolding includes everything in the table. Let’s remove a few of these columns with one easy config block. Put this one in your ApplicationController.
class ApplicationController < ActionController::Base
ActiveScaffold.set_defaults do |config|
config.ignore_columns.add [:created_at, :updated_at, :lock_version]
end
end
Let’s have a look at the local config block. This block goes in the model’s corresponding controller. The config block for the Company model goes in the CompaniesController. ActiveScaffold restricts one model per controller. Now for an example:
class CompaniesController < ApplicationController
active_scaffold :company do |config|
config.label = "Customers"
config.columns = [:name, :phone, :company_type, :comments]
list.columns.exclude :comments
list.sorting = {:name => 'ASC'}
columns[:phone].label = "Phone #"
columns[:phone].description = "(Format: ###-###-####)"
end
end
ActiveScaffold tries to be flexible: change the labels, decide which columns to include, control the columns included per-action, define a default sort order, specify a column label and a column description. Check the API docs to see what’s possible!