带有 ActiveScaffold 和 Lockdown 插件的 Rails

发布于 2024-08-16 03:08:52 字数 1630 浏览 4 评论 0原文

我们的应用程序是使用 Rails 2.3.5 和 ActiveScaffold 开发的。 ActiveScaffold 在运行时添加了相当多的魔力,只需在控制器中声明如下:

class SomeController < ApplicationController
 active_scaffold :model
end

只需在控制器中添加一行,由于 ActiveScaffold 的元编程,所有剩余操作及其相应的视图都可用。由于大部分代码是在运行时添加的,因此在开发模式下,由于没有 class_caching,请求似乎会慢一些。

我们需要添加一个授权层,我的团队选择了 Lockdown 插件,它解析 init.rb 文件,您在其中声明所有授权规则。 Lockdown 存储授权规则的方式是解析 init.rb 文件并评估 init.rb 文件中声明的控制器。因此,对于每个请求,Lockdown 都会评估所有控制器,从而迫使 ActiveScaffold 添加大量元编程,这反过来又使数据库查询找出每个模型的列定义。由于没有 class_caching,这大大减慢了开发中的请求。有时请求几乎需要 30-45 秒。

有没有什么方法可以强制 ActiveScaffold 在 before_filter 中发挥其魔力?如下所示:

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

我尝试了上述所有四个选项,当我发出请求时,浏览器似乎显示加载指示器,但没有任何反应。

任何帮助表示赞赏。 提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月隐月明月朦胧 2024-08-23 03:08:52

Lockdown 仅在开发模式下重新解析 init.rb,因此您无需重新启动应用程序即可进行更改。它会更慢——这是一个便利的权衡。好消息是 Lockdown 在生产模式下只会执行一次解析。

我不使用 ActiveScaffold,因此我无法提供任何帮助,但我认为您会对此感兴趣。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文