{ height: 1%; } - Ruby on Rails and User Interface Design

CSS, UI Design, Ruby on Rails and cheese ... lots of cheese

Ajax Scaffold Plugin Released

Posted by Richard White Tue, 12 Sep 2006 21:09:00 GMT

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?

Comments

  1. Dr Nic said about 13 hours later:

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

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

  2. Pupeno said 11 days later:

    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. Pupeno said 13 days later:

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

  4. Richard White said 15 days later:

    @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”

Trackbacks

Use the following link to trackback from your own site:
http://height1percent.com/articles/trackback/951

  1. From Cheap international flight ticket.
    Cheap flight orlando to rochester ny.
    Cheap flight to london uk. Cheap flight tickets.
  2. From Quick easy cash advance.
    Cash advance loan oregon.
    Advance america cash advance. Cash advance loan. Cash advance. Payday cash advance. Cash advance software telecheck. Cash advance loan wisconsin. National cash loans cash advance network.

(leave url/email »)

   Comment Markup Help Preview comment