AjaxScaffold has been deprecated in favour of ActiveScaffold
Install
The easiest way to install the plugin version of Ajax Scaffold (AS) is to use the inbuilt Rails installer script. Simply run the following command from the root of your Rails app:
ruby script/plugin install svn://rubyforge.org/var/svn/ajaxscaffoldp/trunk
This will fetch the plugin into ‘vendor/plugins’. The files required by the plugin (views, css and js) will then be copied over to the app on startup.
Basic Usage
With the plugin installed simply adding the following line:
ajax_scaffold :model_name_in_lower_case
to the top of any ActionController class, will result in the creation of the swath of CRUD methods required for Richard White’s great AJAX front end.
Then stick this in your layout:
<%= ajax_scaffold_includes %>
Voila!!! The full AS table will then be available at: http://my_server_address/my_controller_name/
For example – lets say we wanted to create a simple user administration interface. First off we generate the users model:
ruby script/generate model user
Then create the users table in the database using the following migration.
create_table "users" do |t| t.column "name", :string, :limit => 255, :null => false t.column "password", :string, :limit => 255, :null => false t.column "created_at", :datetime, :null => false t.column "updated_at", :datetime, :null => false end
Now, generate a controller:
ruby script/generate controller users
Open the controller file, users_controller.rb and add the plugin include:
class UsersController < ApplicationController ajax_scaffold :user end
Create a layout file called users.rhtml:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Users</title>
<%= ajax_scaffold_includes %>
</head>
<body>
<%= @content_for_layout %>
</body>
</html>
Start Webrick, point your favourite browser (Firefox, of course) at http://localhost:3000/users and ……… you should see this:

Now you can go ahead and add, edit, page, and sort your users. Of course in real life having plain text passwords would probably be frowned upon and there is no validation but you get the idea.
Options
So you’ve got a table, what else does it do? Ok, there are a few options that can be passed to the plugin that affect the behaviour and appearance. These are:
except- this takes an array of any of these strings: “create”, “edit”, “delete” and prevents the generation of the corresponding method. This also removes the appropriate elements from the displayed table.
e.g ajax_scaffold :user, :except => [‘create’, ‘delete’]
would create a controller with no create or delete methods.
width – this takes a number representing the width in pixels of the generated table.
e.g ajax_scaffold :user, :width => 500
creates a table of width 500px.
rel_width – this takes a number between 0 and 1 representing the relative width of the table to its containing element.
e.g ajax_scaffold :user, rel_width => 0.7
produces a table of 70% width
rows_per_page – this dictates the maximum number of rows displayed before pagination
e.g ajax_scaffold :user, :rows_per_page => 10
totals – this takes an array of strings representing the names of the columns that you would like totals to be created for. If not null this option causes a totals row to be added to the bottom of the table.
e.g ajax_scaffold :user, :totals => [‘login_cnt’]
would produce a row showing the total number of logins for all the users on the page (assuming of course our model had an incrementing field called login_cnt, see later for another example).
suffix – this emulates the suffix option of the Rails scaffold and when set to true generates all the methods specific to the model allowing for multiple tables to be placed within a single controller (see following section)
Mutiple Scaffolds on a Page
There are two ways to place mutiple tables on a single page, the first (and probably the approved REST / CRUD way) is to create a controller for each model that you wish to have a table for. Setup each table as required using the options to the ajax_scaffold method and then simply include each table in a single rhtml file using a call to render the component.
<%= render_component :controller => '/users', :action => 'table', :params => params %> <%= render_component :controller => '/articles', :action => 'table', :params => params %> <%= render_component :controller => '/pages', :action => 'table', :params => params %>
If however, you don’t want to go down that path, say you just want an admin controller to administrate the user, article and page models the you can do all this with a single file. Simply create an ‘admin’ controller and declare each model with a separate ajax_scaffold call. Make sure to pass the ’:suffix => true’ option:
class AdminController < ApplicationController ajax_scaffold :user, :rows_per_page => 3, :suffix => true, :width => 500 ajax_scaffold :article, :except => ['edit'], :suffix => true, :rel_width => 0.4 ajax_scaffold :page, :except => ['delete'], :rows_per_page => 10, :suffix => true, :width => 400 def index end end
The index page (don’t forget to add the index method) will then look slightly different, with the calls to table now using the prefix of the model name:
<%= render_component :controller => '/admin', :action => 'users_table', :params => params %> <%= render_component :controller => '/admin', :action => 'articles_table', :params => params %> <%= render_component :controller => '/admin', :action => 'pages_table', :params => params %>
This setup (with a bit of data added) gives:

Totalled Columns
Now suppose you want to add totals for the “views” columns in the articles and pages tables. Easy. Just change the declaration in the controller to:
class AdminController < ApplicationController ajax_scaffold :article, :except => ['create','edit'], :suffix => true, :rel_width => 0.4, :totals => ['views'] ajax_scaffold :page, :except => ['delete'], :rows_per_page => 5, :suffix => true, :width => 500, :totals => ['views'] def index end end
Now we get (note the create method has been dropped of the articles table):

Customizing the View
On startup the plugin creates a directory called ajax_scaffold in app/views. This contains all the views required by AS. If you want to alter one of the templates simply copy it to the appropriate views directory and update it.
The search path employed by the plugin is as follows:
- app/views/model_name
- app/views/controller_name
- app/views/ajax_scaffold
So for our example with an admin controller, and then user, article and page models we could override the table.rhtml for all tables displayed by placing our custom template in “app/views/admin”. We could then have a user specific form by placing _form.rhtml in “app/views/user”. The article and page models would keep using the generated form from app/views/ajax_scaffold.
No Responses to “Getting Started with the Ajax Scaffold Plugin”
Sorry, the comment form is closed at this time.












Hi Andrew,
See "this post":http://blog.caronsoftware.com/articles/2007/01/22/ajaxscaffold-and-rails-1-2-1
Cheers
Scott
Hi Patrick, glad you got it sorted. Scott.
I wanted to try the ajax_scaffold_plugin, as the generator is outdated. When I run: ruby script/plugin install svn://rubyforge.org/var/svn/ajaxscaffoldp/trunk nothing happens.
I installed gem install ajax_scaffold_plugin, version 3.2.4. Do I have to install additional software to use the svn command? Thanks in advance
I seem to have the same problem as Martin has, i.e if i run : svn://rubyforge.org/var/svn/ajaxscaffoldp/trunk, nothing actually happens…
And also i have installed the plugin, version 3.2.4. please guide….
Some additional informationI’m on: Rails 1.2.1. MySQL 5.0.11 RadRails 0.72 and WinXP. Basic Rails and database work within without problems.
Thanks in advance to everyone who can help.
I had the same problem. Guess what, i just copied the whole plugin and pasted it under vendor/plugins.
Now it works.
To download the plugin in zip format go to http://rubyforge.org/projects/ajaxscaffoldp/
Thanks I will try your suggestion.
Hi Guys, I think RubyForge was just having a bad day because it all works fine for me now. I would suggest trying the
./script/plugin install svn://rubyforge.org/var/svn/ajaxscaffoldp/trunk
command again.
Cheers
Scott
the plugin worked perfectly for me. thank a lot!
Good day Scott,
I get the following error when I hit the "Create New" button:
RJS Error:
TypeError: element has no properties
I’m using Firefox 2. My model has a few has_many & belongs_to. After I Ok the error it works fine and inserts the new record correctly…
Scott,
Is Ajax Scaffold Plugin Rails 1.2.1 ready? I’m having some problems with getting the Delete buttons to do anything, and I get a whole slew of deprecation warnings….
Thanks,
Eric
@James, that sounds like the error we were getting from using Prototype RC1 / RC0, it went away in 1.2.1.
@Eric, and @James I think both your issues will be solved by 3.2.4 and 1.2.2.
Cheers
Scott
Hi guys, I have a dilemma.
what if you want two versions of the same table to scaffold (one without the delete link). say:
<pre>ajax_scaffold :data_file, :width => 600, :except =>['create','edit', 'delete']
ajax_scaffold :data_file, :width => 600, :except =>['create','edit']</pre>
i need one table to show when i’m logged in and the other when im not. :p
Hi Folks,
I got the simple single table example working and it´s amazing how simple it is using the ajax scaffold plugin. But now I´m trying to implement a simple workflow where I need to redirect to another page, when some action was performed in another page. But I cannot get the redirection working.
I already posted in the forum where you can also find an example of what I´m trying:(http://groups.google.com/group/ajaxscaffold/browse_frm/thread/62bcb14b3c000ef8).
But I got no answer until now and I need to figure out how it works pretty soon. So could someone provide me information on how to implement a workflow, like described in my forum posting?
Thanks & Regards,
Christian
@ Japo, you have two choices I think. You can use 2 controllers, or you could override the _actions template and instead of using the :except declaration you can just do a check on current_user and only show the delete action if required.
@ Christian, I think Lance’s answer on the forum is correct, you can’t use a normal redirect when the request is an ajax one and all the action link requests are ajax. Probably the easiest thing to do is override _actions for yourself and use standard html requests instead of the Ajax.Request the scaffold uses.
Cheers
Scott
Hi,
Is there a way to customize the contoller for ajax scaffolding?
Thanks,
Joe
Something seems to be wrong with param (un)escaping. After reloading an ajax ajaxffold plugin generated site (current svn sources) some params are duplicated, and the names of the duplicates (the keys) are prefixed with "amp;" or "%3B". Example URL:
<pre><code>
http://myserver:1111/statview/update_table?sort_direction=asc&scaffold_id=statview&sort=blog_entries&%3Bscaffold_id=statview&page=1&%3Bpage=1
</code></pre>
And the POST parameters of that request:
amp;page 1<br>
amp;scaffold_id statview<br>
page 1<br>
scaffold_id statview<br>
sort blog_entries<br>
sort_direction asc<br>
Can anyone confirm that? I’m not familiar enough with ajax scaffold yet to spot and fix the bug.
I got AjaxScaffold up and running but it’s only partially working. The main screen displays, but when I click on "Edit" or "Create New", the spinner just goes and nothing else happens. This happens on bothy FF2 and IE6. Any suggestions as to what I should look for?
Minor correction to my last post: There are no POST parameters – the request body is empty. So there are only URL request params.
Hey, Thanks for releasing such an awesome plugin. I am definitely using this for my classifieds project that is almost finished.
@Jon, sounds like you have 1.2.2 but haven’t updated your javascripts. do:
rake rails:update:javascripts
cheers
Scott.
@Railsgrunt – thanks.
@Horst P – thats a new one on me.
To both you guys though. Have you taken a look at our new project http://www.activescaffold.com this is replacing ajaxscaffold and provides some cool new features.
Scott.
I want to add a condition while displaying records where i should i add that condition?
Hi Rita,
You just define a method called conditions_for_{plural_model_name}_collection in your controller and then you can add any normal ActiveRecord style conditions there.
Cheers
Scott
Hi Rita,
You just define a method called conditions_for_{plural_model_name}_collection in your controller and then you can add any normal ActiveRecord style conditions there.
Cheers
Scott
(1) I tried installing using svn command at the top. I got message successfully installed – but there was no directory under plugins.
(2) So I downloaded the zip and manually moved contents under plugins directory. Then followed directions to scaffold my users table. The contents of my users table are shown – but no style missing; click on edit or delete – table is not updated. Click on new. New page is opened. It is as if the page is degraded to HTML rather than ajax. I have rails 1.2.2
Any suggestions – what is happening?
– sunds2
Excellent site, keep up the good work
I’d sweetie to be aware that too!
At Hosts3.com for every hosting account you buy we give you 2 -3 extra free backup hosting accounts at no charge!
Offshore Alpha Master Resellers – Free back up Master Reseller
Hosts3.com is now offering Alpha Master Reseller Hosting
These are Offshore Servers in the OVH Data Center
You can create resellers and master resellers on the Alpha account.
Order Now and Get another Free Master Reseller to backup your data free.
http://www.hosts3.com/whmcs/cart.php?gid=25
Hosts3.com is proud to offer Stable Offshore Master Reseller Hosting
You asked and we delivered!
Offshore Bronze Master Reseller
Offshore Bronze Master Reseller 20GB Space 200GB Bandwidth Unlimited MySql’s Unlimited Hosted domains Unlimited Sub domains Unlimited Email Accounts Free Private Name servers WHM/cPanel 11 Allowed Offshore type content Legal Adult content allowed Server Location: Netherlands
$11.99 /mo order Here:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=31
Offshore Silver Master Reseller
Offshore Silver Master Reseller 40GB Space 400GB Bandwidth Unlimited MySql’s Unlimited Hosted domains Unlimited Sub domains Unlimited Email Accounts Free Private Name servers WHM/cPanel 11 Allowed Offshore type content Legal Adult content allowed Server Location: Netherlands
$18.99 /mo order here:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=33
Offshore Gold Master Reseller
Offshore Gold Master Reseller 80 GB Space 800 GB Bandwidth Unlimited MySql’s Unlimited Hosted domains Unlimited Sub domains Unlimited Email Accounts Free Private Name servers WHM/cPanel 11 Allowed Offshore type content Allowed Legal Adult content allowed Server Location: Netherlands
$21.99 mo Order Here
http://www.hosts3.com/whmcs/cart.php?a=add&pid=34
Offshore Platinum Master Reseller
Offshore Platinum Master Reseller Hosting Unmetred Space Unmetred Bandwidth Unlimited MySql’s Unlimited Hosted domains Unlimited Sub domains Unlimited Email Accounts Free Private Name servers WHM/cPanel 11 Allowed Offshore type content Allowed Legal Adult content allowed Server Location: Netherlands
$25.99 mo order here:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=35
Offshore Resellers Low Prices
Offshore Reseller Hosting Account
Unmetered Space W/ Cpanel Unmetered Resources
Only $9 Per month – Make a lot of money selling to your
own clients. Private nameservers FREE
Order Here:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=26
Offshore Reseller Mini Plan 5 GB Unmetered Resources
Only $3 per month:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=29
Offshore Shared Hosting Only $1 per month for 3 Gb:
FREE 30 Day trial on All Hosting accounts
Just open a Free client account, submit ticket with your
domain name and you will get a FREE 30 day trial hosting:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=9
FFmpeg Hosting Reseller Accounts Available
Reseller FFmpeg Enabled Hosting
10 GB Space Same specs as info below in
shared hosting but you create your
own sub account and charge your own price!
$3 Per month FREE 30 Day Trial
Order Here:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=11
Onshore FFMpeg Enabled Shared Hosting Also Available
Disk Storage 5000 MB
Monthly Data Transfer Unmetered
FFMPEG Video Extensions Enabled!
FREE Video Site Script Installed
If you run out of space we will increase it by 1 gb per request
Adult Content Allowed
Unlimited Addon Domains
Unlimited Parked Domains
24/7 Tech Support
Unlimited MySQL Database
cPanel Latest Version
Unlimited cPanel Features
Fantastico De-Luxe
POP3/SMTP Mails
PHP 5 – MySQL 5 Perl
Cron – FrontPage
GD – CURL
Image Magick
Fantastico
FFMpeg,Mplayer & FLV2Tool Support
Ruby on Rails
Libogg, Liborbis, Lame & MP3 Encoder Support
Frontpage Extension
Cpanel and video tutorials to help you
Free 30 Day Trial Upon Request (Just open a ticket)
$6 per year
Order Here and use the code dp at checkout for $4 Discount:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=13
Hosts3.com Offers A Low Cost Anonymous VPN Service
Surf the internet Privately using a USA IP on an encrypted
connection. We are the lowest cost VPN Provider around.
All user logs are wiped every 7 Days for privacy by admin.
Only $4 month for Shared IP and $8 month for your own dedicated IP
Order shared IP here:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=3
Order Dedicated IP here:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=4
Account Setup info and VPN Software will be emailed within 24 Hours after payment.
Offshore Reseller Hosting Account
Unmetered Space W/ Cpanel Unmetered Resources
Only $9 Per month – Make a lot of money selling to your
own clients. Private nameservers FREE
Order Here:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=26
Offshore Shared Hosting Only $1 per month for 3 Gb:
FREE 30 Day trial on All Hosting accounts
Just open a Free client account, submit ticket with your
domain name and you will get a FREE 30 day trial hosting:
99.9% Uptime
Disk Storage
3000 MB
Unlimited Addon Domains
Unlimited Parked Domains
24/7 Tech Support
Unlimited MySQL Database
cPanel Latest Version
Unlimited cPanel Features
Fantastico De-Luxe
POP3/SMTP Mails
PHP 5 – MySQL 5 Perl
Cron – FrontPage
GD – CURL
Image Magick
Fantastico
Cpanel and video tutorials to help you
Anonymous Domain Registrations if you pay by Liberty Reserve
http://www.hosts3.com/whmcs/cart.php?a=add&pid=9
Windows ASP .Net Hosting Accounts 5GB
HELM 4
web forwarding
backup
MIME types
pre-propagation
scripting support
virtual directories unlimited
secure folders unlimited
custom error page
default document list
antivirus
spam protection
isolated app pools unlimited
usage reports
statistics
file manager
POP3 email accounts unlimited
auto responders
mail forwarders
mailing lists
web based email
MS Access databases unlimited
mySQL databases unlimited
MS SQL server 2005 unlimited
ODBC DSN
DSN-less connection
ftp access
ftp accounts unlimited unlimited unlimited
python
CGI
PERL5
PHP5
MS XML
MS XML parser
MS .NET framework 1.1
MS .NET framework 2
IIS6
Server Side Include (SSI)
ASP scripting
ASP.net 1
ASP.net 2
DNS editor
frontPage extensions
$3 month Order Here now:
http://www.hosts3.com/whmcs/cart.php?a=add&pid=28
Windows VPS Servers
WVPS-1
———–
Windows
15GB of Space
150GB of Transfer
200MB of Ram
Windows Server 2003
Full Off Site Backups Nightly
Remote Desktop (RDP) – Administrator Access
Managed VPS Support
Pro-Active Monitoring – Your VPS goes down we get it back up and notify
Custom Bandwidth Graphing
MS SQL 2008 Databases -> Upon Request
http://www.hosts3.com/whmcs/cart.php?a=add&pid=17
Unmetered FFmpeg Master Reseller Accounts
http://www.hosts3.com/whmcs/cart.php?a=add&pid=44
Offshore (Romania ) VPS Windows or Linux Same Price
- 512MB Dedicated SLM RAM
- Fair-share CPU Usage
- 500GB bandwidth
- 20GB space
- Your choice of Linux or Windows
Romanian Data Center
Linking, torrents and nulled script allowed.
All plans also include:
- Powered by Virtuozzo 4.0
- Choice of Linux (x86 or x64) or Windows 2003 Enterprise x64
- Free offloaded MySQL and Microsoft MSSQL servers for your own needs – saves you plenty of local resources!
- rDNS with a simple request (At this time we’re still working on a control panel for it, but it’s coming soon!)
- Great pings to Asia and the America’s
- Semi-Managed support
http://www.hosts3.com/whmcs/cart.php?a=add&pid=81
- 1GB Dedicated SLM RAM
- Fair-share CPU Usage
- 1000GB bandwidth
- 30GB space
- Your choice of Linux or Windows
http://www.hosts3.com/whmcs/cart.php?a=add&pid=82
Rapidleech Plans – free seperate cpanel account with purchase
10 GB Rapidleech Webspace
Rapidleech Panel Preinstalled
No cpanel not used for webhosting
Can store Files
Unmetered Space
http://www.hosts3.com/whmcs/cart.php?a=add&pid=76
25 GB Rapidleech Webspace
Rapidleech Panel Preinstalled
No cpanel not used for webhosting
Can store Files
Unmetered Space
http://www.hosts3.com/whmcs/cart.php?a=add&pid=77
Seedboxes
50 GB disk space *
Unlimited active torrents **
Unmetered traffic
- 20 Mbps bandwidth limit outbound ***
HTTP access (for downloading)
FTP + SFTP access (for downloading, uploading and managing)
http://www.hosts3.com/whmcs/cart.php?a=add&pid=79
110 GB disk space *
Unlimited active torrents **
Unmetered traffic
- 40 Mbps bandwidth limit outbound ***
HTTP access (for downloading)
FTP + SFTP access (for downloading, uploading and managing)
http://www.hosts3.com/whmcs/cart.php?a=add&pid=80
For any questions or potential discounts etc:
Please open ticket here:
http://www.hosts3.com/whmcs/submitticket.php