Here’s the problem: You have a Ruby on Rails application and its WordPress blog. For the sake of consistency and branding, you’d like to use the same layout in your WordPress blog as you do for your Rails app. Perhaps your blog is one of the main links or tabs in your application’s header.
Why this doesn’t work: You proceed with creating a custom theme for your WordPress blog that looks exactly like your Rails application. Then over the next couple years, you begin to realize how tedious this solution is. You have to copy over your CSS stylesheets from your Rails app, your Javascript files (if your standard layout contains any Javascript elements, like a Twitter widget in the footer or whatever), and your layout images and assets. Then, every time you change or update the layout of your Rails app, you have to copy the changes in your custom WordPress theme. And you cannot just copy the changes, because if you have any Ruby/Rails functionality in the layout, you have to translate them into PHP functionality in your WordPress layouts.
And then there’s the impossible stuff… if anything in your Rails app layout loads information from the database in your Rails app, then you cannot have those elements in your WordPress layout, unless you do something like create an XML or JSON feed in your Rails app and then import it in your WordPress layout. But this is quite tedious still if you want to change any of it!
There’s an easier way.
Include Your Rails Layout Directly In Your WordPress Layout
The solution I found turns out to be quite simple. The basic idea is to create a :partial in your Rails app layout, make it publicly accessible via your config/routes.rb, have it generate and simply return the appropriate html using your controller method, and then import that html (and CSS) in your WordPress layout.
(more…)