为 Rails 应用程序构建扩展框架

发布于 2024-08-27 22:33:48 字数 910 浏览 2 评论 0原文

我正在开始研究为 Rails 应用程序构建用户级插件系统(如 Wordpress 插件)所需的内容,因此我希望得到一些一般性的指示/建议。我所说的用户级插件是指用户可以将其提取到文件夹中并将其显示在管理界面上的包,从而允许他们添加一些额外的配置然后激活它。

这样做的最佳方法是什么?是否有其他开源项目已经做到了这一点? Rails 本身已经为程序员级插件提供了哪些可以利用的功能?有Rails 插件可以帮助我解决这个问题吗?

插件必须能够:

  • 运行自己的迁移(使用 这个?它没有记录)
  • 可以访问我的模型(插件已经可以)
  • 有向视图添加内容的入口点(可以使用content_for 和产量
  • 替换整个视图或部分视图(如何?)
  • 提供自己的管理和面向用户的视图(如何?)
  • 创建自己的路线(或者可能只是宣布其存在并让创建它的路线,以避免插件踩到彼此的脚趾)

我还缺少什么吗?

另外,有没有办法限制插件可以访问有关迁移和模型的表/操作,并限制它们对路由的访问(也许让它们包含但不删除路由)?

PS:我会尽力保持更新,编译我发现的内容和相关答案,以便为其他人提供一种指南。

I'm starting research on what I'd need in order to build a user-level plugin system (like Wordpress plugins) for a Rails app, so I'd appreciate some general pointers/advice. By user-level plugin I mean a package a user can extract into a folder and have it show up on an admin interface, allowing them to add some extra configuration and then activate it.

What is the best way to go about doing this? Is there any other opensource project that does this already? What does Rails itself already offer for programmer-level plugins that could be leveraged? Any Rails plugins that could help me with this?

A plugin would have to be able to:

  • run its own migrations (with this? it's undocumented)
  • have access to my models (plugins already do)
  • have entry points for adding content to views (can be done with content_for and yield)
  • replace entire views or partials (how?)
  • provide its own admin and user-facing views (how?)
  • create its own routes (or maybe just announce its presence and let me create the routes for it, to avoid plugins stepping on each other's toes)

Anything else I'm missing?

Also, is there a way to limit which tables/actions the plugin has access to concerning migrations and models, and also limit their access to routes (maybe letting them include, but not remove routes)?

P.S.: I'll try to keep this updated, compiling stuff I figure out and relevant answers so as to have a sort of guide for others.

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

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

发布评论

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

评论(2

神仙妹妹 2024-09-03 22:33:48

您可能想查看 mephisto,它是一个使用 ruby​​ on Rails 构建的博客软件,并具有附加插件支持。不确定它是否按照您的想法工作,但可能会给您一些很好的见解。源代码可以在 GitHub 上找到。

You might want to check out mephisto, it's a blogging software built with ruby on rails and has add-on plugin support. Not sure if it works how you are thinking of, but might give you some good insights. The source can be found on GitHub.

仄言 2024-09-03 22:33:48

你应该看看 deface gem。它允许自定义 Rails 视图,通过钩子添加内容并替换整个视图/部分视图。 Spree 正在使用这个 gem,所以你也可以查看 spree。除了视图之外,他们还提供其他用于自定义应用程序的解决方案,以便您可以找到问题的更多答案。

You should look at deface gem. It allows to customize rails views, adding content via hooks and replacing whole views/partials. Spree is using this gem so you can look also at spree. Beside views they also have other solutions for customizing application so you can find more answers to your questions.

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