Getting ActiveScaffold 1.1.1 to Work With Rails 2.1.0
When I wrote about a Rails development container I kinda left off with “it all worked and everyone’s happy!” This post goes into a bit of detail about how I upgraded Rails (and ActiveScaffold) to use the newer versions. It’s not that this all that tough or clever but there’s not a lot of information on it.
I followed this wiki page about the process. It definitely gets things going.
Upgrading Rails
So I started off just trying the gem update for Rails:
mattc-mbp:client_app mattc$ sudo gem update rails -y /Library/Ruby/Site/1.8/rubygems/gem_runner.rb:18:in `initialize': uninitialized constant Gem::CommandManager (NameError) from /usr/bin/gem:22:in `new' from /usr/bin/gem:22
Yikes. Well, it turns out that I goofed up my gems installation at some point recently. No big deal:
mattc-mbp:software mattc$ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz --14:28:36-- http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz => `rubygems-1.2.0.tgz' Resolving rubyforge.org... 205.234.109.19 Connecting to rubyforge.org|205.234.109.19|:80... connected. HTTP request sent, awaiting response... 302 Found Location: http://rubyforge.iasi.roedu.net/files/rubygems/rubygems-1.2.0.tgz [following] --14:28:36-- http://rubyforge.iasi.roedu.net/files/rubygems/rubygems-1.2.0.tgz => `rubygems-1.2.0.tgz' Resolving rubyforge.iasi.roedu.net... 192.129.4.120 Connecting to rubyforge.iasi.roedu.net|192.129.4.120|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 246,920 (241K) [application/octet-stream] 100%[====================================>] 246,920 163.26K/s 14:28:39 (162.78 KB/s) - `rubygems-1.2.0.tgz' saved [246920/246920] mattc-mbp:software mattc$ cd rubygem* mattc-mbp:rubygems-0.9.4 mattc$ sudo ruby setup.rb ...done.
Ok now let’s get after it:
mattc-mbp:client_app mattc$ sudo gem update rails -y Updating installed gems... Bulk updating Gem source index for: http://gems.rubyforge.org Attempting remote update of rails Successfully installed rails-2.1.0 Successfully installed rake-0.8.1 Successfully installed activesupport-2.1.0 Successfully installed activerecord-2.1.0 Successfully installed actionpack-2.1.0 Successfully installed actionmailer-2.1.0 Successfully installed activeresource-2.1.0 Installing ri documentation for rake-0.8.1... Installing ri documentation for activesupport-2.1.0... Installing ri documentation for activerecord-2.1.0... Installing ri documentation for actionpack-2.1.0... Installing ri documentation for actionmailer-2.1.0... Installing ri documentation for activeresource-2.1.0... Installing RDoc documentation for rake-0.8.1... Installing RDoc documentation for activesupport-2.1.0... Installing RDoc documentation for activerecord-2.1.0... Installing RDoc documentation for actionpack-2.1.0... Installing RDoc documentation for actionmailer-2.1.0... Installing RDoc documentation for activeresource-2.1.0... Gems: [rails] updated
Ok so Rails is updated, all of the supporting characters for Rails are updated, now it’s time to update the application:
mattc-mbp:app mattc$ rake rails:update (in /Users/mattc/dev/client_app/app) mattc-mbp:app mattc$
Well that was certainly easy. Let’s fire it up and see what shakes loose:
mattc-mbp:app mattc$ script/server => Booting Mongrel (use 'script/server webrick' to force WEBrick) => Rails 2.1.0 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... ******************************************************************* * config.breakpoint_server has been deprecated and has no effect. * ******************************************************************* Exiting /Users/mattc/dev/client_app/app/vendor/plugins/active_scaffold/lib/extensions/action_controller_rendering.rb:26:in `alias_method': undefined method `render_action' for class `ActionController::Base' (NameError) from /Users/mattc/dev/client_app/app/vendor/plugins/active_scaffold/lib/extensions/action_controller_rendering.rb:26 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require' from /Library/Ruby/Gems/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' from /Library/Ruby/Gems/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in' from /Library/Ruby/Gems/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' from /Users/mattc/dev/client_app/app/vendor/plugins/active_scaffold/environment.rb:63 from /Users/mattc/dev/client_app/app/vendor/plugins/active_scaffold/environment.rb:63:in `each' ... 45 levels... from /Library/Ruby/Gems/gems/rails-2.1.0/lib/commands/server.rb:39 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require' from script/server:3
Disaster. Unmitigated, ugly, disaster.
Upgrading ActiveScaffold
Let’s see here. Looks like we have a problem with a method called “render_action”.
Wait a minute, it’s a problem with ActiveScaffold. Maybe I’ll just upgrade it at the same time and then see what happens. (Note: I’m usually pretty good at following the Scientific Method and only changing one thing at once, but this is Rails man!)
mattc-mbp:app mattc$ wget http://activescaffold.googlecode.com/files/active_scaffold_1.1.1.zip ... mattc-mbp:app mattc$ unzip act* mattc-mbp:app mattc$ mv vendor/plugins/active_scaffold ~/tmp/active_scaffold_old mattc-mbp:app mattc$ mv active_scaffold vendor/plugins
Ok, with that fixed at least we should get another error, right?
mattc-mbp:app mattc$ script/server => Booting Mongrel (use 'script/server webrick' to force WEBrick) => Rails 2.1.0 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... ******************************************************************* * config.breakpoint_server has been deprecated and has no effect. * ******************************************************************* Exiting /Library/Ruby/Gems/gems/activesupport-2.1.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method': undefined method `find_full_template_path' for class `ActionView::Base' (NameError) from /Library/Ruby/Gems/gems/activesupport-2.1.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method_chain' from /Users/mattc/dev/client_app/app/vendor/plugins/active_scaffold/lib/extensions/generic_view_paths.rb:33 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require' from /Library/Ruby/Gems/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' from /Library/Ruby/Gems/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in' from /Library/Ruby/Gems/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:509:in `require' from /Users/mattc/dev/client_app/app/vendor/plugins/active_scaffold/environment.rb:63 ... 46 levels... from /Library/Ruby/Gems/gems/rails-2.1.0/lib/commands/server.rb:39 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in `require' from script/server:3
Ok I cheated, having tried this before writing that sentence. Let’s see here. It turns out that there’s a problem with ActiveScaffold that doesn’t let it work with Rails 2.1 yet. The community though has come out with a couple of patches and I’m going to use this one.
mattc-mbp:app mattc$ script/server => Booting Mongrel (use 'script/server webrick' to force WEBrick) => Rails 2.1.0 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... ******************************************************************* * config.breakpoint_server has been deprecated and has no effect. * ******************************************************************* ** Rails loaded. ** Loading any Rails specific GemPlugins ** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart). ** Rails signals registered. HUP => reload (without restart). It might not work well. ** Mongrel 1.1 available at 0.0.0.0:3000 ** Use CTRL-C to stop. DEPRECATION WARNING: config.action_view.cache_template_extensions option has been deprecated and has no affect. Please remove it from your config files. See http://www.rubyonrails.org/deprecation for details. (called from send at /Library/Ruby/Gems/gems/rails-2.1.0/lib/initializer.rb:455)
Ok then, now we’re cooking. I handled that by editing my config/development.rb file as such:
# Show full error reports and disable caching config.action_controller.consider_all_requests_local = true config.action_controller.perform_caching = false # config.action_view.cache_template_extensions = false config.action_view.debug_rjs = true
and then started it up again. Here’s what we got on the first Request:
/!\ FAILSAFE /!\ Mon Jun 23 15:19:24 -0400 2008 Status: 500 Internal Server Error A secret is required to generate an integrity hash for cookie session data. Use config.action_controller.session = { :session_key => "_myapp_session", :secret => "some secret phrase of at least 30 characters" } in config/environment.rb
Ok, easy enough:
Rails::Initializer.run do |config| config.action_controller.session = { :session_key => "_client_app", :secret => "5d02d2049ecc42ca9fe6c5e0e584ef0a" }
Ok, after doing that my first Request worked (it’s the login page), and I was able to get in a few pages. But soon enough I got an error about one of my other plugins:
RuntimeError (We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts): /vendor/plugins/active_scaffold/lib/bridges/calendar_date_select/bridge.rb:6
Ah yes, the succinctly named active_scaffold_calendar_date_select_bridge. Removed. But now we have a new problem when viewing any of the pages with ActiveScaffold:
NoMethodError (You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[]): /vendor/plugins/active_scaffold/lib/extensions/action_controller_rendering.rb:6:in `render'
As with most other errors like this it’s been seen before and addressed. A patch fixed this.
A few other errors did present themselves. One was on using the ‘%’ symbol in my conditions_for_collections() methods on the controllers. You need to escape them with ‘%%’ so that the new ActiveRecord code doesn’t try to print them with sprintf(%).
Changing Render
UPDATE: The patch at lightningdb’s hub seems to fix all of this. Try that first.
Now here’s a good one. I was unable to get lines like this to work:
return render(:action => "refresh_page.rjs")
Rails was coming back with an error like:
Errno::ENOENT (No such file or directory - refresh_page.rjs):
So I then tried to do the RJS inline as such:
render :update do |page| page.replace 'invoice_events-active-scaffold', :partial => 'billing/invoice_events' page.replace 'invoices-active-scaffold', :partial => 'billing/invoices' end
and that failed as well with the following error:
NoMethodError (undefined method `[]' for :update:Symbol):
/vendor/plugins/active_scaffold/lib/extensions/action_controller_rendering.rb:6:in `render'
I investigated the code in the ActiveScaffold action_controller_rendering.rb file and changed it to this:
if self.class.uses_active_scaffold? and (args[0].class == Hash) and ( params[:adapter] || ( args[0] && args[0][:action] )) and @rendering_adapter.nil?
And that seemed to fix it. Notice that it’s the second line where I check to make sure that the argument being passed in is a Hash. If not (and it’s not if this is a render :update) you need to skip that block and just render differently.
Lessons
Well, it’s clear that ActiveScaffold and Rails 2.1.0 don’t all that easily yet. I still need to click every button and view every layout in my app to make sure it all works ok. None of these issues were tough to fix but it scares me a bit to think it’s that far off. I’m going to submit this finding to the ActiveScaffold group and we’ll see if we can get it fixed.
Read more from the Rails category. If you would like to leave a comment, click here: . or stay up to date with this post via RSS, or you can
Trackback from your site.
Leave a Comment
5 Comments so far
Do you have a github for the changes that you’ve made?
Not yet @Kelly Mahan. Should be up there later today or tomorrow though. For now go read my post on the Google Groups for ActiveScaffold and you’ll see the code I changed (it’s one line).
@Kelly Mahan, go get this fork http://github.com/lightningdb/activescaffold/tree/master and you’ll be good.
[...] Getting ActiveScaffold 1.1.1 to Work With Rails 2.1.0 [...]
I have an app that is to go into production in a week or two. Upgrading to Rails 2.1 scares the shit out of me due to the problems I had encountered in ActiveScaffold earlier. I will refrain for the time being! Anyways, thanks for the great update! Sure does help.