Ruby on Rails - 类缓存?

发布于 2024-07-29 05:12:04 字数 638 浏览 8 评论 0原文

我在此处阅读了一篇文章,并使用那里找到的原则为以下内容编写了管理检查我的控制器。 基本上它会检查您所在的控制器,然后我创建一个数组,说明此人是否有权查看该控制器,然后查找并传递它。

文章的作者说读者不应该使用示例代码,因为它有缺陷,他们应该使用他的插件(当然现在已经过时了)。 他说

“由于使用了类变量和类缓存,上述代码在生产模式下运行时存在一些问题。”

我的测试失败了,我认为这可能是由于这个原因,但我不太确定我不应该使用代码的哪一部分。 我有以下内容(在 application.rb 中):

 controller = params[:controller]
 action = params[:action]

但我将其更改为:

controller = self.class.name
action = params[:action]

如何正确访问操作名称? 一般来说,哪些事情在开发模式下可以做而在生产模式下不能做?

I read an article here and I used the principles found there to write a administration check for my controllers. Basically it checks to see what controller you're in and then I create an array saying if this person as permission to see that controller, than find, pass it on.

The author of the article said that readers shouldn't use the example code as it was flawed and that they should use his plugin (which of course is outdated now). And he said

"there are some issues with the above code when running in production mode due to the use of class variables and class caching."

I have a test failing and I think it might be due to this but I'm not quite sure what part of the code I shouldn't be using. I had the following (in application.rb):

 controller = params[:controller]
 action = params[:action]

But I changed that to:

controller = self.class.name
action = params[:action]

How do I access the action name correctly? And in general what kinds of things can you do in development mode that you can't do in production?

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

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

发布评论

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

评论(1

堇年纸鸢 2024-08-05 05:12:04

您是否考虑过基于角色的权限插件?
请参阅以下 stackoverflow 问题:

哪个 Rails 插件最适合基于角色的权限? (请为每个答案提供一个提名)

我不知道您粘贴的代码的生产使用有任何问题。由于可能滥用@@,有问题的插件可能会出现一些问题,但是,我'我没有彻底检查过。

Have you considered a role based permissions plugin instead?
See the following stackoverflow question:

Which Rails plug in is best for role based permissions? (Please provide one nomination per answer)

I'm unaware of any issues with production usage of the code you have pasted in. The plugin in question might have some issues due to a possible misuse of @@ however, I've not inspected it thoroughly.

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