Getting Started with the Ajax Scaffold Plugin
September 2nd, 2006
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.
November 25th, 2007 at 11:18 PM Where Can I Find this plugin? Can I associate in its development ? I would like to have following features in the plugin in addition to what you have mentioned a) Ability to make certain fields in read only mode in create/modify action b) ability to pass a default value to field in create mode c) Support for composite keys d) Generating tree views e) Excel and PDf outputs in user fined templates
November 25th, 2007 at 11:18 PM Hi AJIT, The easiest way to get the plugin is to follow the install instructions at the top of this post. There is a wiki at http://ajaxscaffold.wikipedia.com that links to the RubyForge homepage where you will also soon be able to download a tar. As for helping in the development, you are welcome to submit patches, although a) and b) are already doable a) with custom templates and b) by overriding the appropriate method. I will cover that in a post very soon. As for c) I believe there is a pluing for Rails to cope with composite keys and then it would be a case of overriding the appropriate method. The last two I don't think are really within the problem domain that the scaffold tries to solve. Cheers Scott
November 25th, 2007 at 11:18 PM Great work Scott and Richard: I will now have to play with it. I had been using the generator and was wishing for a plugin. Wish granted :-) Now, how what is the quickest way to convert my existing generator code to using the plugin. I know simple has_many/belongs_to associations have been discussed; yet, what are the current plans for habtm support. I can't seem to get the habtm working on the generator side. Maybe I'll have more luck on the plugin side. Thanks, -- Tom.
November 25th, 2007 at 11:18 PM Hi Tom, Thanks. I will have to have a think about the easiest way to move from generator to plugin and put up a post about it. That is unless you get there first, please feel free to add to the wiki. As a rough guide, you can simply delete any views that aren't customized and add the plugin method call at the top of your controller. You will also need to move any customization of the columns from the model to the controller. Now the habtm support, this is currently a live area, not the easiest thing to make really simple, but we will be giving it a go. Again any progress or ideas are more than welcome. Cheers Scott.
November 25th, 2007 at 11:18 PM I Get Following Error NameError uninitialized constant AjaxController RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace .......... This error occured while loading the following files: ./script/../config/../app/controllers/offices_controller.rb ajax_scaffold/ajax_controller.rb Request Parameters: None Show session dump --- flash: !map:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} What Is Solution ? Regards
November 25th, 2007 at 11:18 PM Hi AJIT, That error is coming from your code. It is AjaxController that can't be found. I would check that you have the name right inside the AjaxController.rb file. I'm not sure why you have a controller under ajax_scaffold/ajax_controller.rb either. To use the plugin you don't need a special controller just add the method call to the top of offices_controller.rb or whichever contoller you wish to use the table with. Scott.
November 25th, 2007 at 11:18 PM I could make it work but does not work with composite keys. I am working on legecy database and have no option but to work with composite keys I am using composite keys http://compositekeys.rubyforge.org/ Also is there way way to make primary field editable ?
November 25th, 2007 at 11:18 PM Hi AJIT Not sure what you mean by make the primary field editable - do you mean make the primary key appear in the table and edit form? Scott.
November 25th, 2007 at 11:18 PM Great work. Now I can start to move from the generator to the plugin. Any idea when some sort of search functionality will be done ?
November 25th, 2007 at 11:18 PM Hi Scott , In legecy databases , the primary key is user defined and not system generated So in new mode , it should be editable Regards , AJIT
November 25th, 2007 at 11:18 PM Hi Frank, Not sure right now, still working on that bit. You can see how to put in your own search in this post: "Extending the plugin":http://blog.caronsoftware.com/articles/2006/09/06/extending-the-ajax-scaffold-plugin For a more complete solution..... watch this space. Scott.
November 25th, 2007 at 11:18 PM Hi AJIT, I think to solve your issue you will need to override any methods in the plugin that deal with model selection and update, there are some pointers in the article on extending the plugin (see previous message). But you will also need to override the actual new and edit methods too. That should give you the functionality you are looking for. Scott.
November 25th, 2007 at 11:18 PM I'm getting the following while using suffix mode: NoMethodError in AdminController#press_contacts_table undefined method `current_page' for #<admincontroller:0xb5e3622c>
November 25th, 2007 at 11:18 PM Doesn't matter if it's suffix mode or not.
November 25th, 2007 at 11:18 PM Hi Smithy, Can you just check you have the latest version from svn (we have been doing some messing about..) If you still have the issue can you post a little more info on your setup. I'm guessing you have something like: and this in your view: Scott
November 25th, 2007 at 11:18 PM Greetings, Thanks for the plugin. It's sweet. I just installed from subversion and tried to scaffold a table with a non-standard primary id like so: It failed with:
Mysql::Error: Unknown column 'items.id' in 'order clause': SELECT * FROM g2_Item ORDER BY items.id asc LIMIT 0, 25
Partial backtrace appended below. I tried scaffolding another table with a standard 'id' primary key and it worked great. cheers, Tom [...] Request Parameters: {"id"=>nil, "scaffold_id"=>"item", "sort"=>nil, "sort_direction"=>"asc", "page"=>1}
November 25th, 2007 at 11:18 PM Hi Tom, I haven't tried a non-standard key before, but looking at the error if you override the default sort method (see this "post":http://blog.caronsoftware.com/articles/2006/09/06/extending-the-ajax-scaffold-plugin) then you should be able to get it to work. Cheers Scott.
November 25th, 2007 at 11:18 PM Just installed the plugin, and trying to replace a generated Ajax Scaffold. After creating a new controller and view, it worked but displayed the old generated scaffold (that I had customised slightly). I discovered this was due to the search path employed by the plugin. I.e. 1. app/views/controller_name 2. app/views/model_name 3. app/views/ajax_scaffold So i renamed the old app/views/model_name and tried again, but now get this error:
cannot convert nil into String RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/vendor/plugins/ajaxscaffoldp/lib/ajax_scaffold_plugin.rb:193:in `+' #{RAILS_ROOT}/vendor/plugins/ajaxscaffoldp/lib/ajax_scaffold_plugin.rb:193:in `table_setup' #{RAILS_ROOT}/vendor/plugins/ajaxscaffoldp/lib/ajax_scaffold_plugin.rb:177:in `table'November 25th, 2007 at 11:18 PM Hi Tommy, Oops, that should of been: model / controller / ajax_scaffold. Its sounds like it was working fine before you followed my (incorrect) instructions above (I have now updated the post). I would change everything back. You would expect to see the old scaffold, if you don't want that just delete the customized files. You may however find issues with updates to the templates you have customized. Cheers Scott.
November 25th, 2007 at 11:18 PM Thanks Scott for the quick reply, but I still get the same error. This is the situation in more detail. I had a user model, Users controller, and the generated ajax scaffold which then had some minor customisation. In trying to test the Ajax Plugin, I ... 1. Installed the plugin 2. Created a new controller called Users2 3. Created a users2.rhtml 4. Deleted app/views/users so the plugin didn't pick this up At this point if I view http://127.0.0.1:3000/users2/list I get the error above. If I restore app/views/users then i see my old scaffold again. Is it strange that app/views/users is not actually my model name, since this is user?
November 25th, 2007 at 11:18 PM Ah, yes. There is a problem at the moment with mixing the generated and plugin controllers at the same time. This is due to differences in the way ScaffoldColumn is implemented. If you move the old controller out of the app directory then you might (we only just found this out, so I'm not yet sure of the fix) just get the uncustomized plugin scaffold. You could then customize the templates by copying the ones you want to change to views/user. Scott.
November 25th, 2007 at 11:18 PM I have just tried changing the model described in User2 controller to a different one (:question) and this gives me a different error when viewing http://127.0.0.1:3000/users2/list
NoMethodError in Users2Controller#table undefined method `current_page' for #<users2controller:0x39764e0> RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/vendor/plugins/ajaxscaffoldp/lib/ajax_scaffold_plugin.rb:200:in `table_setup' #{RAILS_ROOT}/vendor/plugins/ajaxscaffoldp/lib/ajax_scaffold_plugin.rb:177:in `table'November 25th, 2007 at 11:18 PM Tommy, Can you get the latest version of the plugin from svn and try again, this error is something that should be fixed now. Cheers Scott.
November 25th, 2007 at 11:18 PM Hi Tommy, Smithy, These problems are fixed now and the plugin and generator should now work together. (The svn has the latest version) and we will be packaging it up a bit later today. Scott.
November 25th, 2007 at 11:18 PM I have just run ... ... and still no change. Also now noticed that controllers with the generated ajax scaffold are not working correctly. The tables appear with the correct number of rows, but there is no data displayed. If I click 'Edit' then the data appears ok in the form.
November 25th, 2007 at 11:18 PM Hi Tommy, I just created a test app, with one generated and one plugin controller and I see the same. If you move the ajax_scaffold.rb out of lib the plugin will work, but the generated controller won't and visa versa. Unfortunately (for the moment), I don't really have a solution at present other than not to use the two together...... We'll have to take a look at it and see if we can resolve the differences. Cheers Scott
November 25th, 2007 at 11:18 PM @Tommy: That was a problem that we fixed when going to press. The version up there now *is* the official release. I apologize for the confusion caused by our shuffling of release files (we didn't realize anyone would notice :( ).
November 25th, 2007 at 11:18 PM Cheers both of you, I will have to give it a go a little later, as I am just investigating a problem with pagination, nested tables and disabled javascripts. "link to post":http://groups.google.com/group/ajaxscaffold/browse_thread/thread/bf38f78bd10f435c/5370a16c006e72d3#5370a16c006e72d3
November 25th, 2007 at 11:18 PM Hi Tommy, Actually you will probably find its still broken, seems there is a problem with generated scaffold using a version of the generator prior to 3.1.6. We are looking at it at the mo. Cheers Scott.
November 25th, 2007 at 11:18 PM Now, its fixed, thanks Richard. Scott.
November 25th, 2007 at 11:18 PM Thanks for your work. Just reinstalled and all my models now appear to work except I still get an error with my 'user' model.
TypeError in Users2Controller#table cannot convert nil into String RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/vendor/plugins/ajaxscaffoldp/lib/ajax_scaffold_plugin.rb:194:in `+' #{RAILS_ROOT}/vendor/plugins/ajaxscaffoldp/lib/ajax_scaffold_plugin.rb:194:in `table_setup' #{RAILS_ROOT}/vendor/plugins/ajaxscaffoldp/lib/ajax_scaffold_plugin.rb:178:in `table'To try help identify the cause, I cleared mt User model so it is now just ... ... and that didn't help. My users table is ...create_table "users", :force => true do |t| t.column "login", :string t.column "password", :string t.column "firstname", :string t.column "surname", :string t.column "phone", :string t.column "mobile", :string t.column "email", :string t.column "address", :string t.column "is_delegate", :boolean t.column "division_id", :integer t.column "is_admin", :boolean endNovember 25th, 2007 at 11:18 PM Scott, Can you give an example of a custom _form.html? As an example, let's say you didn't want "password" column displayed in the list, but you do want it in the form. Keep up the good work!
November 25th, 2007 at 11:18 PM @Tommy: Have you solved this yet? I've been at RailsConf and got a little behind in answering things. I just tried to emulate your problem but it all works for me. What do you have in the controller? @Chris: Sure. For your example you would create the columns you want using the scaffold_columns class variable (we are looking at an :without_columns [or something] parameter so you can just leave one column out). Then basically just create a form in the following style:
November 25th, 2007 at 11:18 PM Scott, My controller is just ... I didn't get a chance to look at it anymore last week, but just tried again and it is working (very strange). Anyway I can rollback from source control and give it another go, but for now consider it fixed. Thanks
November 25th, 2007 at 11:18 PM Scott, There's a really minot typo .. The example incorrectly uses 'max_rows'
November 25th, 2007 at 11:18 PM Hi Tommy, Thx, post is updated. Glad its all working for you now. Scott.
November 25th, 2007 at 11:18 PM Is there any way to apply formatting to a column? I'm stuck working against a MS SQL Server database which only has datetime fields and I only want to display the date (without the time).
November 25th, 2007 at 11:18 PM Is there same way for ajaxscaffold to display relationships to other databases, and let the user enter it with selects ? Thanks.
November 25th, 2007 at 11:18 PM Hi Michael, Sorry for the delay in responding, been a hectic week. You could override this method in the ajax_scaffold lib:
module Helper include AjaxScaffold::Common def format_column(column_value, sanitize = true) ..... end endThat should let you customize the formatting. Or you could customize the row template, do a check to see when you are rendering the date and create a helper to format the view. Scott.November 25th, 2007 at 11:18 PM Hi Pupeno, The way to do this is to create a custom _form.rhtml template for the model you are talking about and populate that with "collection_select" tags containing the data you want displayed. You will need to populate the collections in your action or a helper. Scott.
November 25th, 2007 at 11:18 PM I just installed the plugin module and setup the code for a model per the instructions in the getting started howto for the plugin. The ajax scaffold page renders, but the top and bottom of the border for the table extends beyond the table on the right hand side. I also have the ajax scaffold generator installed, and on a different model the table renders properly when created with the generator. I can send a screen capture or other artifacts if it would be helpful. Ideas?
November 25th, 2007 at 11:18 PM I've tried several different variations of trying to install the plugin based on your instructions and I get the following: svn: Can't connect to host 'rubyforge.org': Connection refused Personally I would prefer to install it as an svn external with the following: ruby script/plugin install -x svn://rubyforge.org/var/svn/ajaxscaffoldp/trunk That doesn't work either. Any clues? Cheers, Walter
November 25th, 2007 at 11:18 PM @Terry - I haven't come across that before. It would probably be easier if you sent me over a couple of screenshots, and maybe the two controllers. Nothing immediately springs to mind though. @Walter - I think you may just of been being unlucky with RubyForge. This works for me ruby script/plugin install svn://rubyforge.org/var/svn/ajaxscaffoldp/trunk and I have the externals set up on a couple of projects too. Cheers Scott.
November 25th, 2007 at 11:18 PM Regarding legacy tables: I've sent a bug and patch today to fix the issue Tom has. It fixes issue with my legacy table. I didn't checked if it works with my customer primary key, probably the has to be patch as well. I just replaced line 133 in vendor/plugins/ajaxscaffoldp/lib/ajax_scaffold_plugin.rx with
plural_name = eval("#{class_name}.table_name") || singular_name.pluralizeAnd it works for me.November 25th, 2007 at 11:18 PM Yep, my problem. Needed to open up hole in firewall for svn protocol. Cheers, Walter
November 25th, 2007 at 11:18 PM Thanks for that Sergey, I'll add it to the next release. @Walter - glad its working. Cheers Scott.
November 25th, 2007 at 11:18 PM Here's a silly question or two. I'd like to email a screenshot of the table issue I posted about a couple days ago. What format do you want the doc containing the screenshot (MS Word, html-formatted email, etc), and which email address should I sent the information to?
November 25th, 2007 at 11:18 PM Guys, I've been working with the generator, and this plugin is phenomenal. I'm working now on tying this in with permissions, which should be an easy fix and should allow for extending other custom functionality, ie: each interface having CRUD, but some interfaces having more than CRUD (my Products table ties with a Skus table, which in turn ties to Finishes, Materials, and Sizes). So my _row.rhtml will dynamically load an edit link, delete link, and a skus link (to list skus for the product) based on the current admin's role and the role's permissions. Also working on some hot habtm action (already had _some_ luck with the generator on that front). I'll post here later if I come up with anything juicy, but in the meantime, I'd appreciate any thoughts on the latter. Thanks VERY much for this plugin!
November 25th, 2007 at 11:18 PM Another observation on the problem of the top and bottom border width: in Firefox, the table renders perfectly - the width of the table body matches the width of the top and bottom trimming. In IE6, with the plugin only, the problem occurs. In IE6, the generator-based code works fine. I lined up two ajax scaffold pages - one created with the generator and the other with the plugin. The rounded top and bottom trim was the same width in both cases, but the width of the individual table cells containing the data was slight more narrow than the generator based table. Tonight I will do a comparison of the rendered html to find the physical difference, but I'd appreciate it if someone could confirm that the plugin-based code works for them in IE6.
November 25th, 2007 at 11:18 PM Hi Terry, I've just looked at this and I see the same problem with the plugin on IE. I will try to have a look at this later - any input is of course more than welcome.... Cheers Scott.
November 25th, 2007 at 11:18 PM @Anthony - Cheers. The habtm stuff keeps cropping up and I just haven't had time yet to go through it. Its on the radar though. @Terry - Update, just to confuse things I have also got installs that work fine on IE. Brilliant..... Scott.
November 25th, 2007 at 11:18 PM After some investigation, I have narrowed the IE6 top/bottom border issue to the presence of a single line in the generated html for the page. Here are the details of the experiment: I created two ajax_scaffold pages from the user model described in the howto above - one via the ajax_scaffold generator, and the other using the plugin as described in the howto. I verified that the generator-based page renders properly, and that the the plugin-based page has an extended border. I saved the resultant html for both pages via browser view-source as working.html and broken.html. I placed these files in the scaffoldp/public folder so that the following url would render the pages with working styles and images: http://localhost/demo6/vendor/plugins/ajaxscaffoldp/public/broken.html I modifed each html file so that all references to css, js and image files would be valid in the new location. I verified that the behavior of these pages was as expected: broken.html had an extended border and working.html did not. Doing a side by side comparison of these files, and moving/replacing successively smaller pieces of working.html into broken.html, I determined that removing the following line from broken.html fixed the border issue: OPENANGLEBRACKET script src="/demo6/vendor/plugins/ajaxscaffoldp/public/javascripts/dhtml_history.js?1159500944" type="text/javascript"> OPENANGLEBRACKET /script CLOSEANGLEBRACKET (OPENANGLEBRACKET and CLOSEANGLEBRACKET added here to protect the script ref.) When I add this line back into broken.html, it is again broken. I have not drilled any deeper than this yet, but if this doesn't ring any bells, I'll keep investigating.
November 25th, 2007 at 11:18 PM Hi Terry, Thanks for all your investigation, I think that will be enough for me to fix the issue. I'll be putting out a release tomorrow which I plan to have this fixed in. Thanks Scott.
November 25th, 2007 at 11:18 PM Hi Scott, great work. I was able to install and properly run the generator, but I am having difficulty getting the plugin. If I do: ruby script/plugin install svn://rubyforge.org/var/svn/ajaxscaffoldp/trunk the script exits after a pause, without errors, and nothing gets installed. I must be doing something wrong... Thanks for your patience! Giuseppe
November 25th, 2007 at 11:18 PM Hi Guiseppe, I have just tried that command and it works for me. Other people who have had similar problems have found that their firewall was blocking access to the svn at rubyforge. You could just download the zip or the tar from here: http://rubyforge.org/projects/ajaxscaffoldp/ Cheers Scott.
November 25th, 2007 at 11:18 PM Hi Scott, thanks for the feedback. I am sure you have much better things to do, but--I had already downloaded the zip/tgz package from rubyforge, and have been unable to properly install it. I guess I cannot figure out how to install a plugin from a local source (name and location of source folder, command options, etc.). It seems like a very basic task, but I can't seem to find the relevant info on the web. My attempts to do: ruby script/plugin install local_path_to_plugin_dir have failed. Apologies for abusing this post and your time, and thanks again. Giuseppe
November 25th, 2007 at 11:18 PM Hi again Scott, never mind my previous post. I have just discovered the miraculous fact of life (on rails) that installing a plugin quite simply means to place its directory structure into vendor/plugins (hoping I am not missing something). WOW :-) I feel ready to try and get AS and Golberg to act nice to one another... Ciao, Giuseppe
November 25th, 2007 at 11:18 PM Hi Giuseppe - nop thats all it takes ;) Glad you got it working. Scott.
November 25th, 2007 at 11:18 PM I grabbed the latest plugin code today, and it looks like you fixed the border issue - that's great! I'm quite curious about what was causing the issue. I'll do a diff with the previous version. Thank you Scott! -terry
November 25th, 2007 at 11:18 PM Is it just me, or do the contents of get rewritten every time you restart the server? If so, is this the default behavior for plugins, or is this specific to this plugin? Assuming my controller is "products" and I want to alter the code for , I know I can get around this by creating an altered version at , but I want to make several controllers reflect the same changes. Surely there's an easy way to do this (not necessarily by disabling the plugin's apparent rewriting "feature")? PS: I love to imagine how this will likely turn out: I'll be humbled and awed by the simplicity of the solution. Thanks rails! Sincerely, a former PHP guy.
November 25th, 2007 at 11:18 PM @Terry, we just used the IE star hack to force the width to behave. @Anthony, you are right at the moment that is the behaviour although we are looking to change that. The easiest way to achieve the result you are looking for is to change the template in the plugin directory then that will be copied across. Of course you will need to remember to copy the change over when you update the plugin. Cheers Scott
November 25th, 2007 at 11:18 PM First off, I'd like to also say thanks for all the work on this plugin. This is really good stuff. I'm trying to use the ajaxscaffold as a plugin. If I use the script/plugin install; then it works just fine. But, I would rather use: gem install ajax_scaffold_plugin This installs just fine, but no matter what I do (require 'ajax_scaffold_plugin' or anything else), I can't seem to get: ajax_scaffold :model_name_in_lower_case Should the plugin work as a gem? (I haven't copied anything over to my project). Thanks! -- Marcus
November 25th, 2007 at 11:18 PM Hi Marcus - the plugin needs to be installed on an app by app basis so installing it as a gem won't work. It has to go in vendor/plugins. The gem is just there as another archive. Cheers Scott
November 25th, 2007 at 11:18 PM How do I go about integrating ajaxscaffold with substruct? I tried going into the substruct plugin area, modifying a controller and layout file, but it crashed. BTW, great work on this plugin!
November 25th, 2007 at 11:18 PM Hi. Regarding the legacy primary key\table names, I have a fix that seems to work. I modified default_#{prefix}sort somewhere near line 374 be the following.
def default_#{prefix}sort eval("#{class_name}.table_name") + "." + eval("#{class_name}.primary_key") endIt takes the table_name and primary_key from the model class. I am still learning so there might be a much better way.Cheers, Michael.
November 25th, 2007 at 11:18 PM @Henry, sorry for some reason I only just saw your comment. However, I've never used Substruct myself so I can't really help you there. Others may though so you could try asking on the forum. @Michael, those evals shouldn't be required. Apart from that though this is bascially the code that is in the upcoming version, so your issue will remain fixed in that. Thanks for the feedback. Cheers Scott.
November 25th, 2007 at 11:18 PM when I run: ruby script/plugin install svn://rubyforge.org/var/svn/ajaxscaffoldp/trunk from the command line, nothing happens. I decided to tack a "2" on the end just to test to see what happens and I get the same result from above, absolutely nothing. ?
November 25th, 2007 at 11:18 PM Hi Mark, that works for me. Are you behind a firewall? Scott.
November 25th, 2007 at 11:18 PM Ive just set up using the plugin, have: class OriginController < ApplicationController ajax_scaffold :origin end class Origin < ActiveRecord::Base ajax_scaffold :model_name_in_lower_case has_many :leads, :foreign_key => 'howdidyouhear' end [ .. ] fire up mongrel on 3000, and when I hit http://localhost:3000/origin I get: `const_missing': uninitialized constant Origin [.. ] Can anyone tell me what glaring mistake I must be making here? Thanks
November 25th, 2007 at 11:18 PM Hi R, you don't need to put the scaffold call in your models only the controller. Cheers Scott.
November 25th, 2007 at 11:18 PM "Hi Mark, that works for me. Are you behind a firewall? Scott." Well, I don't think so... but maybe. Wouldn't the ruby install call show some kind of error if it cannot connect? I get back no response at all. Thanks, Mark
November 25th, 2007 at 11:18 PM What if I just download the entire plugin zip from rubyforge. Do I just unzip it in the base directory? I tried that, but I get a undefined method `ajax_scaffold' for MyJobsController:Class.
November 25th, 2007 at 11:18 PM @Mark - you would unzip it in vendor/plugins. Scott.
November 25th, 2007 at 11:18 PM Great Plugin, what if I wanted to display the id next to each entry?
November 25th, 2007 at 11:18 PM Hi Hesham, to display the id you would need to configure the columns yourself. You can see how to do this in "this post":http://blog.caronsoftware.com/articles/2006/09/05/defining-custom-columns-with-ajax-scaffold-plugin Cheers, Scott.
November 25th, 2007 at 11:18 PM It doesnt works for me. It produces an error: TypeError in UsersController#table can't convert nil into String Cheers, LEo
November 25th, 2007 at 11:18 PM Hi Leonardo - not sure what that would be. I would try submitting a slightly more verbose version to the "forum":http://groups.google.com/group/ajaxscaffold Scott
November 25th, 2007 at 11:18 PM Hi. nice work! but I have a quick and simple question: Where do I put the users.rhtml file? I tried to put it into the /views/controller_name, /views/model_name, /views/ajax_scaffold and i always get bland html and errors saying that Rico isn't available. Thanks!
November 25th, 2007 at 11:18 PM Hi Scott. How can i update some field`s values (like date of creation), which are not displayed by custom _form.rhtml PS: Sorry for my dumb question, but i have`t enough patience for reading RoR docs till the last and starting with your great plugin in my app :) Leon
November 25th, 2007 at 11:18 PM @Martin, have you included all the javascript in your headers? @Leon, Rails will update any updated_on / updated_at / created_on / created_at fields automagically for you so you don't have to edit those yourself. If you want your form to contain those fields for hand editing then you will need to define your own custom form. Cheers Scott.
November 25th, 2007 at 11:18 PM Thanks for all your customising ajax scaffold which I used a lot. But I am facing problems with Ajax scaffold when I use ajax scaffold with salted hash login generator on the same model. The login generator uses session[:user] to store the user information for a valid user and ajax scaffold uses the same session variable to store the sort column and the sort direction etc. As the session[:user] is used all over along code to check for the valid user it cannot be changed do you have any better solution for the same? NAYAK (Vishwanath Nayak K)
November 25th, 2007 at 11:18 PM @Mark : same thing for me, the script/install does not do anyhting. I am definitely not behind a firewall. - I unzipped under the Vendor/plugins directory In my case C:\...\Depot\vendor\plugins\ so that I now have a ajax_scaffold_plugin-3.2.2 folder in it now - I reloaded rails, as plugins are loader at boot time Now it works... and it is a wonder !! Thank you !
November 25th, 2007 at 11:18 PM @NAYAK - I don't think there is anything you can do. It would of been a good idea to access the user session through a method then you could change that to access session[:user][:current] or something similar. As it stands I think you will have to change everything or no use the scaffold. Sorry. Scott.
November 25th, 2007 at 11:18 PM I could not get the plugin to install, so I copied ajax_scaffold_plugin-3.2.2 directory into \app\vendor\plugins I modified the app/controller/user_lanuages_controller.rb adding ajax_scaffold :user_language to it. I created a user_languages.rhtml the contains that is identical to your example users.rhtml file in app/view/user_languages All I get is the normal html list when I go to http://localhost:3000/user_languages/ I read a post up further that sounded similar, and your suggestion was to ensure that the javascript was in all the headers. I am not sure what you mean by that. I followed the instructions at the top and do not see any instructions on javascript. Thanks
November 25th, 2007 at 11:18 PM First off, I wanted to say great job on the plugin, I started out using the generator and switched over as soon as I heard of the plugin. Made life much easier. I've run into some issues when trying to display multiple tables on the same page. The problem is that the tables are all coming from the same controller (eg Repairs). The Repairs controller has a custom conditions_for_repairs_collection and each of the tables on the page is passing a different id for the condition so that the tables are different. I've tried with and without suffix and no matter what the id generated for the table seems to always be "repair" which certainly isn't good to have 10 of the same id. Oddly enough a lot of the tables are actually functional, except for any sort of paging. Is there some other means to make each table generated distinct so that they stop interfering with one another?
November 25th, 2007 at 11:18 PM @4tc.org - this is the line I was talking about: <%= ajax_scaffold_includes %> it needs to go in the header of your page. Sounds like you aren't getting the css which is the same issue. @Rich, you can just create them from different controllers, which is probably the best thing to do anyway with the REST / CRUD thang. The multiple tables from a single controller only works if they are scaffolding different models not if you want 10 repair tables with different contents. Scott.
November 25th, 2007 at 11:18 PM @scott/4tc.org: I seem to have the same issue. I followed the sample .rhtml file which should place the javascript includes in the header (right?), and no luck. Like 4tc.org, I was also forced to perform a manual install.. perhaps there's something I didn't do correctly?
November 25th, 2007 at 11:18 PM Yea, creating separate controllers wont really work as it's a dynamic number of tables being displayed, could be 1, could be 10. I think I'll just have to switch that section to only display tables as they don't really need to be able to edit the values directly in that section anyway. Thanks for the quick response.
November 25th, 2007 at 11:18 PM Scott, Thanks just to clarify. Here is what I have in the view page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html> <%= javascript_include_tag :defaults %> <head> <%= ajax_scaffold_includes %>And Controller ThanksListing user_types
</head> <body> <%= @content_for_layout %> </body> </html>November 25th, 2007 at 11:18 PM I get the following error undefined method `ajax_scaffold' for CategoriesController:Class when I run it. I have two other classes with generated ajax_scaffold that work (and still work after I installed the plugin). I know all the plugin code is in the right place as I can see it. I Did create the layout file with the includes. I tried putting in under ../views/layouts where I think it should go and also under ../views/categories this is my categories_controller.rb file class CategoriesController < ApplicationController ajax_scaffold :category def index end end I tried with and without the def index, but as you can tell it does not get that far anyway thanks Jeff
November 25th, 2007 at 11:18 PM ok, I got it to work by putting: require 'ajax_scaffold' in my model I didn't see that this was required in the tutorial, is it supposed to be? Or is it picking up something from the generater version?
November 25th, 2007 at 11:18 PM I'm running against SQL Server and I'm getting this error. DBI::DatabaseError: Execute OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server The column prefix 'clients' does not match with a table name or alias name used in the query. HRESULT error code:0x80020009 Exception occurred.: SELECT * FROM (SELECT TOP 1 * FROM (SELECT TOP 1 * FROM clients ORDER BY clients.id asc ) AS tmp1 ORDER BY clients.id DESC) AS tmp2 ORDER BY clients.id asc The sql statement isn't valid if I take it out and put it in Query Analyzer I replaced clients with tmp1 and tmp2 where appropriate and the query ran. I'm using the generator, any help would be appreciated.
November 25th, 2007 at 11:18 PM Hi David, Can't really help you there I'm afraid, no real experience of MS SQL, although it sounds like an Active Record bug in the generation of the SQL. You are best off asking generator (which is now deprecated by the way) questions on the "forum":http://ajaxscaffold.stikipad.com. Cheers Scott.
November 25th, 2007 at 11:18 PM This is superb! I just followed your example and had this running in under five minutes. I'll have to step back and reconsider some (much more difficult) things I was attempting via "straight rails". Thank you!
November 25th, 2007 at 11:18 PM I have a patch that adds a prefix to the scaffold_id, making ajax_scaffold play friendly with login_generator. I had to change default_scaffold_id to: :default_scaffold_id => "ajax_scaffold_#{singular_name}" As well as a couple other changes to support this, but it all seems to be working now. And it doesn't get cloberred by login_generator. How should I submit the patch? Ryan
November 25th, 2007 at 11:18 PM Hi Ryan, probably the best thing to do is post the fix on the forum, then people using the current version can use it. The latest version of the plugin changes things a lot, so any patch will no longer be applicable. Thanks. Scott.
November 25th, 2007 at 11:18 PM Hay hay Well nice plugin. But there is a little problem at my hack. May be I forgot something to do? The List Action runs wuiet right (Table looks good), but if I press one of the Edit Buttons, there will be an error: --- RJS error: Could not convert JavaScript argument" nsresult: .... NS_ERROR_XPC_BAD_CONVERT_JS location JS Frame ../javascripts/prototype.js?... line 1206 data: no --- If I press the okay button another modal window is opened with a lot of HTML Output is shown. It is too long to view at the end. And after that the line I wanted to edit is hidden in the table. After a refresh it is shown quiet right. Any ideas whats going wrong here ? bye
November 25th, 2007 at 11:18 PM I'm trying to use ajax scaffold plugin with Rail 1.2.1 and I keep getting errors. Maybe materials given is not a valid Ruby identifier? (eval):1:in `evaluate_read_method': compile error (eval):1: parse error, unexpected tFID, expecting '\n' or ';' def materials given?; query_attribute('materials given'); end ^ (eval):1: parse error, unexpected kEND, expecting $ def materials given?; query_attribute('materials given'); end Any ideas?
November 25th, 2007 at 11:18 PM Solvation: I used the application.rhtml for corporate design of all other rhtml pages at the view/layouts directory. That was a bad idea and the problem in my app. Dont know really why, but in my opinion the access via DOM is different for every page ... bye
November 25th, 2007 at 11:18 PM Does this plugin work with Rails 1.2.1/Prototype 1.5? I can get the table to display, but clicking any of the actions just leads to the spinner spinning forever and no request showing up in the log. Any thoughts? Thanks.
November 25th, 2007 at 11:18 PM Hi Andrew, See "this post":http://blog.caronsoftware.com/articles/2007/01/22/ajaxscaffold-and-rails-1-2-1 Cheers Scott
November 25th, 2007 at 11:18 PM Hi Patrick, glad you got it sorted. Scott.
November 25th, 2007 at 11:18 PM 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
November 25th, 2007 at 11:18 PM 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....
November 25th, 2007 at 11:18 PM 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.
November 25th, 2007 at 11:18 PM 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/
November 25th, 2007 at 11:18 PM Thanks I will try your suggestion.
November 25th, 2007 at 11:18 PM 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
November 25th, 2007 at 11:18 PM the plugin worked perfectly for me. thank a lot!
November 25th, 2007 at 11:18 PM 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...
November 25th, 2007 at 11:18 PM 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
November 25th, 2007 at 11:18 PM @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
November 25th, 2007 at 11:18 PM Hi guys, I have a dilemma. what if you want two versions of the same table to scaffold (one without the delete link). say: i need one table to show when i'm logged in and the other when im not. :p
November 25th, 2007 at 11:18 PM 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
November 25th, 2007 at 11:18 PM @ 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
November 25th, 2007 at 11:18 PM Hi, Is there a way to customize the contoller for ajax scaffolding? Thanks, Joe
November 25th, 2007 at 11:18 PM 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: And the POST parameters of that request: amp;page 1
amp;scaffold_id statview
page 1
scaffold_id statview
sort blog_entries
sort_direction asc
Can anyone confirm that? I'm not familiar enough with ajax scaffold yet to spot and fix the bug.
November 25th, 2007 at 11:18 PM 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?
November 25th, 2007 at 11:18 PM Minor correction to my last post: There are no POST parameters - the request body is empty. So there are only URL request params.
November 25th, 2007 at 11:18 PM Hey, Thanks for releasing such an awesome plugin. I am definitely using this for my classifieds project that is almost finished.
November 25th, 2007 at 11:18 PM @Jon, sounds like you have 1.2.2 but haven't updated your javascripts. do: rake rails:update:javascripts cheers Scott.
November 25th, 2007 at 11:18 PM @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.
November 25th, 2007 at 11:18 PM I want to add a condition while displaying records where i should i add that condition?
November 25th, 2007 at 11:18 PM 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
November 25th, 2007 at 11:18 PM 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
November 25th, 2007 at 11:18 PM (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