How to make a rails feature modular, maintainable and reusable?
OK let's assume I have an awesome looking rails app with somes Posts, which can be commented and voted on. It's online and people love it.

Now imagine a client comes up and tells me "Hey, this app looks good ! Could I have just the same one, but with my logo and votes also on comments ?"

So ok I clone the app, make the changes, then I deliver the tweaked app to the client, and then I get back to my original app and continue to make it better. 

A couple on months later another client come and also wants the same app (now improved) but with votes also on comments.

Of course I realize cloning the app in the first place what a crappy idea.

What I'd like to know is how would you do from the beginning to make it as easy, maintainable and DRY to reuse the feature made for the first client in the second's project ?

Then, imagine lots of clients come with lots of different requested features. Now you realize it would be just awesome to be able to 'build' a new app with just this feature or this one, but not this one, and so forth.

How would you achieve that ?

I imagine git branches could be a nice way to achieve that, or maybe Rails Engines/Gems, or I don't know, but I'm definitely not git or rails skilled enough to clearly see in my mind how it would be.

So my dream answer here would be your precise workflow on solving this problem.

Thanks !
How to make a rails feature modular, maintainable and reusable?
===

OK let's assume I have an awesome looking rails app with somes Posts, which can be commented and voted on. It's online and people love it.

Now imagine a client comes up and tells me "Hey, this app looks good ! Could I have just the same one, but with my logo and votes also on comments ?"

So ok I clone the app, make the changes, then I deliver the tweaked app to the client, and then I get back to my original app and continue to make it better. 

A couple on months later another client come and also wants the same app (now improved) but with votes also on comments.

Of course I realize cloning the app in the first place what a crappy idea.

What I'd like to know is how would you do from the beginning to make it as easy, maintainable and DRY to reuse the feature made for the first client in the second's project ?

Then, imagine lots of clients come with lots of different requested features. Now you realize it would be just awesome to be able to 'build' a new app with just this feature or this one, but not this one, and so forth.

How would you achieve that ?

I imagine git branches could be a nice way to achieve that, or maybe Rails Engines/Gems, or I don't know, but I'm definitely not git or rails skilled enough to clearly see in my mind how it would be.

So my dream answer here would be your precise workflow on solving this problem.

Thanks !