I've got an application with news, products, printed issues and some other smaller objects which is live and working well.
Now I would like to use this app for two or three other websites that have different content, CSS, views and even some logic needs to be adjusted. What is now the best practice to go for?
What I came up with so far:
Branches: master which stays untouched. Website1, website2 and website3 branched off with respective changes.
Forks: Fork the base app and create 3 more repositories with the changes.
Engine: Turn app into some kind of Engine or alike, mount it in a new app and override everything there.
Keep everything as as and create some configuration file to enable/disable features etc.
Any ideas are highly appreciated!
Related
Recently I built an rails app for a local business. They like this app so much that they've gotten a couple of other local businesses interested in having their own version of the app.
Here lies the problem that Im uncertain how to fix. The core business logic behind the app would be the same for these new and future customers(about 80% of the code). Whereas each customer would have their own static pages, as well as their own stylesheets.
Ive thought about multi-tenancy, but these guys are picky enough that it honestly seems easier to build the app function the way they want, as opposed to building around DB stored customer preferences(perhaps I'm wrong here).
I would like configure this application so that I can push changes to the core business logic without overwriting the customer specific portions of the site. Perhaps creating a second repo which only contains the customer specific content.
How do I configure this app/Git repo so that I can personalize the app without creating a bunch of parallel repos?
As Meagar pointed out the solution to this scenario is to encapsulate the core business logic of these applications into a Gem that can be reused later down the road.
I have a rails app which contains some fairly generic functionality (eg managing users). I would like to use that common functionality in other rails apps without copying it. The hard part seems to be that this code contains a number of models, controllers and views.
I know that gems and plug-ins allow code to be shared but they seem to apply more to sharing utility and library functionality rather than core parts of an app.
Any advice on how to do this would be greatly appreciated.
We are working with a Rails engine to share functionality between client projects and have gotten quite far with it. The engine contains controllers, models, views, and even routes. It provides core functions needed in each project (access to our in-house content management system) so projects don't have to start from scratch.
Most of the code has been structured in a way that it can be easily extended or overwritten where needed in the projects (mostly by subclassing). It's distributed as gem.
I can't show you code (it's not open-source), but I can point you to some helpful resources:
Rails 3 Plugins - Part 1 - The Big Picture
Rails 3 Plugins - Part 2 - Writing an Engine
Rails::Engine documentation
Plugin Authors: Toward a Better Future
Hope this helps!
Making copies is not always bad. That's why I ask about the reasons you don't want to copy the code.
If you create a 'library', you must ensure that every application will use it in the same manner. Or you have to prepare the 'library' for every possible difference between your applications which use it.
If you share the code, you are adding a dependency to your program. Any change in that shared code will affect more than one application.
Often it's much simpler to copy the code to another application, because then your may apply any modification without thinking about others.
Are you sure that managing users is so generic that you will not make any application-specific changes to it?
What about creating links to the files/directories that have the MVC? That is better than making copies.
Background:
We have app a, b, and plan to add more apps into this same application. The apps are similar enough they could share many views, assets, and actions. Currently a,b live in a single rails app(2.3.10). c will be similar enough that it could also be in this rails app.
The problem:
As we continue to add more apps to this one app, there's going to be too much case logic that the app will soon become a nightmare to maintain. There will also be potential namespace issues. However, the apps are very similar in function and layout, it also makes sense to keep them in one app so that it's one app to maintain(since roughly 50% of site look/functionality will be shared).
What we are trying to do is keep this as clean as possible so it's easy for multiple teams to work on and easy to maintain.
Some things we've thought about/are trying:
Engines. Make each app an engine. This would let us base routes on the domain. It also allows us to pull out controllers, models and views for the specific app. This solution does not seem ideal as we won't be reusing the apps any time soon. And explicitly stating the host in the routes doesn't seem right.
Skinning/themes. The auth logic would be different between the apps. Each user model would be different. So it's not just a skinning problem.
In app/view add folder sitea for sitea views, siteb for siteb views and so on. Do the same for controllers and models. This is still pretty messy and since it didn't follow naming conventions, it did not work with rails so nicely and made much of the code messier.
Making another rails app. We just didn't want to maintain the same controller or view in 2 apps if they are identical.
What we want to do is make the app intelligently use a controller based on the host. So there would be a sessions controller for each app, and perhaps some parent session controller for shared logic(not needed now). In each of these session controllers, it handles authentication for that specific app. So if the domain is a.mysite.com, it would use session controller for app a and know to use app a's views,models,controllers. And if the domain is b.mysite, it would use the session controller for b. And there would be a user model for a and user model for b, which also would be determined by the domain.
Does anyone have any suggestions or experience with this situation? And ideally using rails 2.3.x as updating to rails 3 isn't an option right now.
Devise does exactly this. You would do well to check out its architecture and apply that architecture to your own case.
You will have multiple separate Rails applications. The shared code will be a separate project, perhaps distributed as a gem or at least a separate Git repository. The shared code will include many controller actions and many view templates that are there to be sensible defaults, and which will be overridden in some apps but not in others.
All the custom code for application A will belong in a project solely devoted to containing the custom code for application A. It will be its own fully-functioning Rails application and will depend heavily on the majority of the sensible defaults provided by the shared code in the shared-code project.
I've used the theme support plugin before and dynamically set the theme based on the request uri:
http://mattmccray.com/svn/rails/plugins/theme_support
It will probably need some work to support Rails 2.3.
Update: Looks like there's a rewrite: https://github.com/dasil003/rails-multisite
Sounds like you want to make the 'base' app a plugin and use that in each of your site apps. You can use something like svn-extern so it's automatically updated whenever something changes.
What's the best way to organize multiple, slightly-varied incarnations of one Rails app?
The incarnations vary on css, images, database and domain. The app/logic is otherwise exactly the same. There is a chance public-facing path names of some routes will need to vary, but still the same route structure.
So I'm thinking of having one installation of the app and managing these changes in the environment.
DB is obviously already set up nicely for this. CSS and image paths I imagine would be easy enough to make environment-aware. Routes shouldn't be too difficult either I guess, in theory anyway.
The reason I'm writing this post is because I'm sure this problem must been solved. Is there an existing "skins" gem or something I can use for this? Otherwise, any comments on my planned approach would be greatly appreciated! I'm using Rails 3.
Why not just maintain separate branches in your revision control system?
A lot of it depends on why you're trying to achieve this. We currently serve four different 'apps' on a few different domains and subdomains from the same Rails Application. We do this because we have different clients that want to see different features of our product. For instance every product shares the idea of customers, contracts, merchants and many other models but they want to have the site branded differently, tab and menu items named differently and have some parts of the site inaccessible to certain people.
You've outlined CSS and images as your main concerns so I'll stick to those, however we've also had to employ ideas to remedy layouts, authorization and javascript amongst other issues and resources.
For simplicity sake I'll call a skin what in our case is a separate product.
Our app has a plugin that sets up some environment variables based on the incoming domain. Then based on these variables our Rails app will source different layouts and partials as appropriate. These layouts then reference the appropriate JS and images which are stored in locations that make sense for designers and frontend devs. For instance customer.js may store the usual customer operations, then in a sub directory there may be a customer.js for a skin and it will extend the main customer.js file (we use Dojo to do this).
In other areas where security is a concern we have libraries that do what is required based on the environment variables that were set by our domain gem.
We also have to provide dynamic branding so again these views and layouts have helpers with logic in them to determine where images should come from and so on.
For CSS we use SASS, so a lot of the time you can use mixins for colours and images. We do this by having a root SASS file with layout information that uses variables for colours and images. Then we'll require those colour files and image files into the root SASS as required.
The answer may be better if you give some information on how you are determining between these two skins. As far as I know there are domain plugins out there already that could help you determine which site the user is trying to access. As for how to organise your application to render the correct CSS, images, JS and so on hopefully what I've outlined helps a little.
I developed a rails app for a school alumni site.
Now another school wants me to develop a similar site for them.
I want to reuse the app. Data structure will be same but the actual data will be different. Design layout will be similar but design itself will be different.
One option is that I just copy the app and modify it. But in this case, I need to manage 2 apps as they evolve.
Another option will be to make the app generalized and customizable (Database will be separated though). Views will have a lot of a lot of branches.
I could use on database for multiple apps but I am sure it will require a lot of jobs.
Another option will be to move controllers and models to plugins so that 2 apps share them.
Do you have any experience with such a case? If so, can you share it with me?
Thanks.
Sam
This might be a little unorthodox, but if you're using git, you can create two branches
one for the school alumni site
one for the similar site
The root code will stay in the master branch. Your development flow would then be:
branch off the master
make edits
pull edits into master when satisfied
pull the master changes into the branches.
You can continue to locally modify the branches as needed, but you will need to be careful about introducing conflicting edits between master/branch.
If there is any way to avoid the complexity of forking your code into two separate applications you should do it.
Making the application generalized and customizable as you are suggesting moves your one off consulting project into something closer to a standalone product (which might be more profitable).
You'd be surprised how far you can get with different stylesheets, layouts and judicious use of localisation.
2 apps will share:
Models
Helpers
Controllers
They won't share:
Views
I am not sure about database yet.
I may separate views using skin concept like:
app/views/app1/...
app/views/app2/...
I am still thinking about database.
I'm using git submodules and symlinks. There's a submodule to the shared project in Rails.root/shared. Then there's symlinks from app/models to shared/app/models, and so on.