The Evolution of Means

Installing Rails Inside a PHP App

You can put a rails app right in on top of certain PHP apps. Why? In my case, I wanted to harness rails migrations, but I’m using the php CodeIgniter framework. CI has a plugin you can add that gives you migrations in the CodeIgniter app. But I wasn’t able to get this to work, and I’m a rails guy. I’m pretty comfortable with migrations in rails.

CodeIgniter adopts several Rails conventions. Like it has an applications/ directory with models/, helpers/, controllers/ and views/ directories. It also has a database abstraction layer it calls Active Record. It sticks the actual web application in public/ .

What I did was just generate a new rails application and then copy it into the CodeIgniter directory. Isn’t that nuts? Since CodeIgniter’s directories are all named slightly differently from rails (applications vs apps, logs vs log) there were no conflicts. Inside of the web app’s directory I was able to run rake db:migrate, after configuring database.yml. I also installed the rspec framework. While this is mostly useless, since I can’t really use rspec to test php models (without going to a lot of extra work anyway), it does work well for making functional tests, where I’d make requests with the capybara gem on my application that’s running a php backend (and a lot of js like a lot of newer apps). Capybara doesn’t care who’s creating the web pages, it just tests from the browser’s perspective. So it works great.

The downside is, I don’t have rails running on the server. And why would I? It’s a php app. Deploy anywhere right? So then the migrations you run in local development can’t easily be replicated in the production environment. Aww, so close.