views:

90

answers:

1

Our application is developed using Rails 2.3.5 along with ActiveScaffold. ActiveScaffold adds quite a bit of magic at run time just by declaring as following in a controller:

class SomeController < ApplicationController
 active_scaffold :model
end

Just by adding that one line in the controller, all the restful actions and their corresponding views are made available due to ActiveScaffold's meta programming. As most of the code is added at runtime, in development mode requests seems to be little slower as there is no class_caching.

We needed to add a authorization layer and my team has chosen Lockdown plugin which parses an init.rb file where you declare all the authorization rules. The way that Lockdown stores the authorization rules is by parsing the init.rb file and evaluating the controllers declared in the init.rb file. So for every request Lockdown evaluates all the controllers thereby forcing ActiveScaffold to add lot of meta programming which in turn makes db queries to find out the column definitions of every model. This is considerably slowing down the request in development as there is no class_caching. Some times are requesting are taking almost 30-45 seconds.

Is there any way to force ActiveScaffold to do its magic in a before_filter? Something like the following:

class SomeController < ApplicationController
 before_filter :init_active_scaffold
 private
   def init_active_scaffold
     self.class_eval do
       active_scaffold :model
     end
   end
end


class SomeController < ApplicationController
 before_filter :init_active_scaffold
 private
   def init_active_scaffold
     self.instance_eval do
       active_scaffold :model
     end
   end
end


class SomeController < ApplicationController
 before_filter :init_active_scaffold
 private
   def init_active_scaffold
     self.class.class_eval do
       active_scaffold :model
     end
   end
end


class SomeController < ApplicationController
 before_filter :init_active_scaffold
 private
   def init_active_scaffold
     self.class.instance_eval do
       active_scaffold :model
     end
   end
end


I tried all the above four options, when I make a request, browser seem to show the loading indicator but nothing is happening.

Any help is appreciated. Thanks in advance.

A: 

Lockdown only reparses init.rb in development mode so you can make changes without restarting the application. It will be slower - a convenience trade off. Good news is that Lockdown will only do this parsing once in production mode.

I don't use ActiveScaffold, so I can't offer any help there, but thought this would be of interest to you.

stonean
stonean: I understand the performance difference of using lockdown in development vs. production. But the problem with using lockdown along with activescaffold as I explained above, is taking almost 15-30 seconds in development mode which is why I wanted if there is any way of making activescaffold stuff using a before filter.
satynos