Rails 抛出一个 Rails 插件化开发的重要且有趣的问题

gazeldx · 2013年01月20日 · 最后由 gazeldx 回复于 2013年01月24日 · 3587 次阅读

我想为我的故事 http://mystory.cc/ 源代码在: https://github.com/gazeldx/mystory/ 开发一些新功能。比如“民间股神”模块。但这个模块并不是所有博客用户都需要的。 PHP 中的 DISCUZ 可以用安装插件的方法来实现,把模块相关的功能源代码放在一个文件夹中。 Rails 有什么好办法吗?

设计一个接口,然后做个 gem 咯 这问题不怎么有趣嘛

把那些增量功能设计成 Gem 呗 小的做成普通 Gem 就可以了,大的要设计成 Rails engine 然后要设置一张列表确定哪些用户使用哪些插件。然后就设计一些注册插件用的接口,在那些 Gem 中调用,这样的就差不多了吧。

discuz 的插件一开就是全站开的,不是针对某用户的呀 :)

PHP 这种东西不可能是 Ruby 的对手,和装备精良的 Rails 比更加差太远了。。

这是应用设计问题和框架没关系

#4 楼 @wuwx 不好意思,我说的就是如何实现 DISCUZ 那种一个文件夹中存放所有该插件的文件。@iBachue 说的很对。谢谢!

有人能举一个 github 上的例子吗?十分感谢。

#8 楼 @gazeldx redmine 有一堆各种 plugin

#9 楼 @ywencn 我去看了,已经找到例子,多谢。见: https://github.com/edavis10/redmine/tree/master/extra/sample_plugin/ Rails 强大!

#10 楼 @gazeldx 别跟着 Redmine 学代码,惨不忍睹

#11 楼 @knwang 谢谢。我正想下载呢,可惜 github 被墙了,解决见 http://ruby-china.org/topics/8249 。所以我在 gitcafe 建了一个 mystory 的库: https://gitcafe.com/gazeldx/rubyblog

http://guides.rubyonrails.org/engines.html Engines can be considered miniature applications that provide functionality to their host applications. A Rails application is actually just a “supercharged” engine, with the Rails::Application class inheriting from Rails::Engine. Therefore, engines and applications share common functionality but are at the same time two separate beasts. Engines and applications also share a common structure, as you’ll see throughout this guide.

需要 登录 后方可回复, 如果你还没有账号请 注册新账号