Getting ActiveScaffold to work under Ruby on Rails 2.3

I had started an application using Ruby on Rails and I wanted to try out ActiveScaffold as a replacement for standard scaffolding. I’d seen ActiveScaffold in action before but I’d never used it. I knew that ActiveScaffold dynamically generates application pages using a standard format, and if you change the format it updates all of your application’s pages — unlike standard scaffolding where you have to tweak each and every page. For the application I’m working on it sounded like a huge time-saver, so I decided to try it out.

I was trying to install ActiveScaffold for Ruby on Rails using the steps shown on the Active Scaffold – Getting Started tutorial. However, when I installed ActiveScaffold using the instructions the Mongrel web server I use for development would die as soon as I tried to restart it, dumping a large list of errors:

earl@earl:~/projects/TotalWorldDomination > script/server
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/
module/aliasing.rb:33:in `alias_method': undefined method `_pick_template' 
for class `ActionView::Base' (NameError)
        from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/
core_ext/module/aliasing.rb:33:in `alias_method_chain'

… and the error messages continued, filling up the entire screen.

I quickly figured out that the problem was that I was using Rails 2.3.2, and the release version of ActiveScaffold was for Rails 2.2.x. The tutorial was for Rails 2.2.x, not 2.3.x.

Since I’d just commited all of my changes to my Subversion repository before installing ActiveScaffold I reverted to the previous version of my application, removing any files installed by ActiveScaffold.

I checked the README for ActiveScaffold on GitHub and installed the following branches:

script/plugin install git://github.com/activescaffold/active_scaffold.git -r master
script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3

After that Mongrel loads just fine:

earl@earl:~/projects/TotalWorldDomination > script/server
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server

Following the tutorial I added this to my layout:

<%= javascript_include_tag :defaults %>
<%= active_scaffold_includes %>

And I added this to one of my controllers (just so I could test out ActiveScaffold with one model):

  layout "admin"
  active_scaffold

At this point if I try to pull up a view for the controller I just modified I get a “Template is missing – Missing template admin.erb in view path vendor/plugins/active_scaffold/frontends/default/views” error.

Active Scaffold - missing admin view

This error is misleading, since (checking GitHub) there are no admin.* files in active_scaffold/frontends/default/views in any of the four ActiveScaffold branches. It’s not a view that comes built into ActiveScaffold, even though the tutorial makes it sound like a built-in layout, it’s the name of a layout file for your application.

In my case the layout that I’d modified in the previous step was application.html.erb, and it was the only layout in my small application. I made a copy of the file named admin.html.erb:

cd app/views/layouts
cp application.html.erb admin.html.erb

Then following advice I found in the ActiveScaffold forums I commented out everything in all of my standard-scaffold-generated controllers, leaving only the lines:

  layout "admin"
  active_scaffold

… in between the “class” and “end” lines for each controller.

Once I did that ActiveScaffold worked fine.

One note: If you do get any “Request Failed (code 500, Internal Error)” errors, check log/development.log for hints about what’s going on, it’ll usually tell you what the problem is.

Hope you found this useful.