Search code examples
ruby-on-railscontrollersactivescaffold

activescaffold controller missing activescaffold work around


I have a 3yr old application that has some controllers with some very unrestful actions. I'm trying to implement a new resource that has relationships to some of the older ones, but I want to use activescaffold to manage the nested resources rather than try to rewrite the plate of spaghetti that is the rest of the codebase. I need to write new controllers for the nested resources that use activescaffold, but I can't lose the old controllers, and I can't rename them either. how can I get the activescaffold config to pick up the config for the nested resources from the new controller rather than trying to look at the conventionally named controller for the configuration?

thx for your help :)

-C


Solution

  • You can use the active_scaffold_controller_for override method. From the ActiveScaffold documentation - http://www.activescaffold.com/docs/api-core

    class ApplicationController < ActionController::base
    
      protected
    
      def self.active_scaffold_controller_for(klass)
        return FooController if klass == Bar
        return "#{klass}ScaffoldController".constantize rescue super
      end
    end