rails engines 用法

engines 可以将app中的modle controller view 都放在plugin中,和rails设计初衷不一致,DHH一度比较反对engines。rails的解决方案使用generator。而generator都是放在app下,这样一堆代码都放在app下,也不是很好。相比generator,engines还是有优点的,在rails2.3 它又重新归来(听说django设计是使用mini_app)。
缺点:
Rails Engines allow you to package up some of a Rails app (controllers, models, views, routes, libs) and put them in a plugin that can be included into a new Rails app, thereby giving it the functionality you had in the engine. That sounds good, but what about the downsides of using an engine? Well, you can’t override or extend any of the functionality from the engine in your main application. You can hack at the plugin, but now you’ve made it difficult to update. So what do you do if you want to add or alter a method to a controller or model? What do you do if you want to change the look and feel of a view? You have to copy everything into your main application. Boo!

Rails Engines also don’t allow you to package up migrations, assets, plugins, initializers, etc… All the fun stuff that you’ve come to know and love about a Rails application.

1 install plugin engines:script/plugin install http://svn.rails-engines.org/plugins/engines
其中controller,view helper 中的方法可以override。详细的见rails-engines.org.
2 script/generate plugin comment
3 在vender/plugin 下讲app db public copy在comment/下,降你的route,或要copy的东东写成脚本,为了下次在多个项目中使用。
4 具体的看engines源码和readme

从bd71x得知 还有一种方式warp drive(http://www.metabates.com/2009/10/07/introducing-warp-drive-for-rails/)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值