开发者

How can I reuse components and widgets in other Rails apps? Is that a good idea?

开发者 https://www.devze.com 2023-01-24 17:16 出处:网络
I have built mini widgets that consist of a model, a controller a couple of stylesheets and a couple of lines of开发者_如何学编程 javascript. Whenever it turns out that I need something like that in t

I have built mini widgets that consist of a model, a controller a couple of stylesheets and a couple of lines of开发者_如何学编程 javascript. Whenever it turns out that I need something like that in the next app I am building, i have to do some copypasta from the app where I had built them. Needless to say, that is not fun.

So I've heard about component frameworks like Cells, Apotomo and Parts, which promise to alleviate this chore, but I couldn't find any discussion around them or any other significant community activity, usage stats, and so on, to indicate their adoption. Except for a few blogposts, the community is oddly silent about component frameworks. That makes me wonder: are they a good idea and if they are not, why not?


Reusing code from multiple projects is in general a good idea. It reduces the need to maintain multiple different sets of code and makes it easier to implement functionality quickly.

I would create a repo specifically for those components and simply pull it into your codebase as a plugin. As for how to structure this component its identical to any other gem available on github , providing you namespace items correctly you can port it easily between applications without issue.


The plugin and gem paradigms for Ruby/Rails are well established. They are probably the best routes for re-use of components


Cells usage stats (since September 2010): https://rubygems.org/gems/cells

0

精彩评论

暂无评论...
验证码 换一张
取 消