AjaxScaffold has been deprecated in favor of ActiveScaffold

Ajax Scaffold is nice, but generated code just doesn’t scale well. There’s too much effort required to make cross cutting changes.

I really like Ajax Scaffold but it’s really hard to upgrade when a new version comes out. I usually spend a couple hours diffing all my scaffolds with a newly generated one.

I couldn’t agree more and we now have an answer to those problems: an Ajax Scaffold plugin. Creating a scaffold is now as easy as:

class WidgetController < ApplicationController

  ajax_scaffold :widget

end

Need extra control over the displayed data?

class WidgetController < ApplicationController

  ajax_scaffold :widget

  @@scaffold_columns = [
    AjaxScaffold::ScaffoldColumn.new(Task, {:name => "name",
         :sort => "name.downcase" }),
    AjaxScaffold::ScaffoldColumn.new(Task, {:name => "tags",
         :eval => "widget.tag_names.collect{|t|h(t)}.join(', ')" })
  ]

end

And it can scale up to be just as customizable as the generated code. Need to customize the form partial? Just copy _form.rhtml into your controller’s view directory and change it. If you’re new to Ajax Scaffold you will probably want to play around with a generated scaffold first to get a feel for how all the pieces (controllers, views, etc) fit together as the plugin code is a bit more complex (but should make sense if you’ve used the Ajax Scaffold generator).

The plugin is almost a direct port of the functionality of the existing Ajax Scaffold generator with a few extra conveniences tacked on (total rows, sorting by method, etc). One major difference is that the scaffold_columns definitions have been moved from the model to the controller (The generator will be going this way in it’s next release).

We will be versioning the two projects in parallel to keep confusion to a minimum. The plugin release is 3.2.0 which will be the same version as the next generator release that incorporates some of the changes the plugin has made (scaffold_columns in the controller).

Many thanks go to Scott Rutherford for writing the bulk of the code as well as the howto guides (which you can get to via the Ajax Scaffold wiki). Ready to get started?

6 Comments

  1. Yippee! Now we have magical scaffolding! Thanks Scott and Richard!

    (Sorry for the excessive !’s … but they do help to express my joy :)

    • Cliff Steele
    • Posted September 18, 2006 at 3:07 pm
    • Permalink

    This really is an excellent plugin – especially the addition of totalling on columns. Many thanks for your efforts.

    • Jonathan del Strother
    • Posted September 19, 2006 at 10:40 am
    • Permalink

    Nice work. One quick point, though – this doesn’t play nicely with autotest. Copying the files over in init.rb prompts autotest to retry the test, which re-initializes the plugin, which re-copies the files, etc etc. So any test failures are repeated over and over again until they pass.

    I got around this by altering init.rb to not copy any files unless app/views/ajax_scaffold doesn’t exist, but obviously this isn’t ideal – it won’t copy over any new files if the plugin is updated, for one thing.

  2. Excellent! The ajaxscaffold plug-in is excellent!
    Is there some reason assosiations are not picked up automatically generating a select element in the form.
    The options in the select would have the foreigns ids and if the content would be a problem, just getting the to_s of the object would be a good solution. Yes, I’ll show a useless object pointer untill to_s is implemented, which is trivial.
    Thanks and please keep with the good work!

  3. How do you do a custom pagination with the plug in (to be able to sort by relationships) ?

    • Richard White
    • Posted September 28, 2006 at 7:23 am
    • Permalink

    @Pupeno: Associations are a sticky topic, but are also the number 1 thing on our list (besides fixing bugs). We won’t get to autogeneration soon enough but we’ll be ramping up in that direction by at least making adding relationships a bit easier. For now you just have to override _form.rhtml.

    You can sort a column either in SQL or in memory. You want to do the latter so just specify the :sort option in your ScaffoldColumn definition. If you had User.tasks, then you’d want the value of :sort to be “tasks”