AjaxScasffold plugin & Deployment Problem (and solution!) 

ActiveScaffold is a great plugin for rails that I have found myself using over and over again. If you have not heard of it, check it out — it’s bomb.

I discovered a problem with deploying the application to a QA or Production type environment — AjaxScaffold copies it’s files into the application’s /public directory when the server is restarted — and it needs r/w access to a /public directory to do so. Not too secure….

I friend of mine found great article that outlines this problem & the solution here.

The fix essentially involves skipping the creation of files when the app is running in production mode. The file patched is init.rb or install.rb — the later file is patched instead for edge versions of ActiveScaffold.

Here’s the mod:

# Include hook code here
require 'ajax_scaffold_plugin'

ActionController::Base.send(:include, AjaxScaffold)
ActionView::Base.send(:include, AjaxScaffold::Helper)

# copy all the files over to the main rails app, want to avoid .svn
# Do not copy in production mode!!! And catch errors and log them
if ENV['RAILS_ENV'] != 'production'
    source = File.join(directory,'/app/views/ajax_scaffold')
    dest = File.join(RAILS_ROOT, '/app/views/ajax_scaffold')
    FileUtils.mkdir(dest) unless File.exist?(dest)
    FileUtils.cp_r(Dir.glob(source+'/*.*'), dest)

    source = File.join(directory,'/public')
    dest = RAILS_ROOT + '/public'
    FileUtils.cp_r(Dir.glob(source+'/*.*'), dest)

    source = File.join(directory,'/public/stylesheets')
    dest = RAILS_ROOT + '/public/stylesheets'
    FileUtils.cp_r(Dir.glob(source+'/*.*'), dest)

    source = File.join(directory,'/public/javascripts')
    dest = RAILS_ROOT + '/public/javascripts'
    FileUtils.cp_r(Dir.glob(source+'/*.*'), dest)

    source = File.join(directory,'/public/images')
    dest = RAILS_ROOT + '/public/images'
    FileUtils.cp_r(Dir.glob(source+'/*.*'), dest)
  rescue Exception => ex
    RAILS_DEFAULT_LOGGER.error "AjaxScaffold error while copying the AjaxScaffold files to the application directory. (#{ex.t_s})"

Again, thanks to devblog.famundo.com for this solution!