I'm currently migrating a legacy Rails 2.x.x app to Rails 3.2. I'm doing this by breaking down specific portions of the monolithic application into small specialized applications. My trouble lies in code duplication. The smaller applications will share the same client side code for the general layout, javascript, and css. How can I package the layout and client side code so that it can be shared between the separate stand-alone applications? My initial guess is this could be done with a mountable engine. But I'm not sure whether or not that is overkill.
-
git submodule ot engine are fine – apneadiving Apr 16 '13 at 08:42
-
If u like more "low level" solution you can always create [symbolic links](http://en.wikipedia.org/wiki/Symbolic_link#POSIX_and_Unix-like_operating_systems) to folders containing layouts. – Oto Brglez Apr 16 '13 at 08:48
-
Duplicated: http://stackoverflow.com/questions/2669477/sharing-code-between-two-or-more-rails-apps-alternatives-to-git-submodules – fotanus Apr 16 '13 at 12:48
1 Answers
I wrote a blog http://blogs.pigrider.com/blogs/22 to show how I build a shared layout engine for using in multiple applications in Rails 3.2 step by step.
A glance to my blog:
This blog shows how I build an Rails engine to share layout among multiple applications step by step. The way I build the shared layout engine in this blog may be not the best. However, I only want to give some clue to those who are still struggling in building this kind of engine.
The name of my engine is "PigriderLayout". Run the command rails plugin new PigriderLayout --mountable -d mysql to create a new engine project. Here I use -d mysql because I use MySQL as database. You may change it to fit your own database, and don't forget to add an according database gem into Gemfile. I put gem 'mysql2', '0.3.11' into my Gemfile.
Generate a controller for all shared layout contents. Run this command rails generate controller main globalLayout aboutUs contactUs. Here I have three actions in this main controller. Then, edit the file config/routes.rb, let it looks like:
PigriderLayout::Engine.routes.draw do
match "AboutUs"=>"main#aboutUs", :as=>:aboutUs
match "ContactUs"=>"main#contactUs", :as=>:contactUs
endIn the directory app/views/pigrider_layout/main, you should see three view files now. They are globalLayout.html.erb, aboutUs.html.erb, and contactUs.html.erb. You may write anything you want in aboutUs.html.erb and contactUs.html.erb. In the file globalLayout.html.erb, I write:
......

- 82
- 1
- 2
-
Please, try to read this http://stackoverflow.com/help/deleted-answers, to get more understanding how to **not** answer. Namely: "Answers that do not fundamentally answer the question": **barely more than a link to an external site** – Radim Köhler Aug 15 '13 at 05:23