Alfa Jango Blog Engineering, Software, and Entrepreneurship

Posts Tagged ‘Ruby’

How to Include Your Rails App Layout in Your Wordpress Theme (or any PHP application)

Tuesday, February 23rd, 2010

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…)

How to Monitor Your Rails/Passenger App with Munin

Thursday, February 11th, 2010

Munin is a great tool to monitor resources on your server, showing graphs over time, so that you can analyze resource trends to find what’s killing your server before it causes major problems. It is also very configurable and can be made to profile and graph just about anything via plugins. And with a couple tricks, you can get it to monitor your Phusion Passenger application with ease.

If you already have Munin installed and working, and just want to know how to get the Passenger Plugins working, you can skip directly to Install Munin Passenger Plugins, Configure Munin for Passenger Stats, and be sure to read the Gotcha.

(more…)

Cool Libraries for Ruby

Monday, December 28th, 2009

I was just thinking about how often I come across cool projects and libraries people are developing for Ruby. We all know you can create cool web applications Ruby on Rails, but what about all of the other cool things you can do with Ruby. So, I decided to put together a short list with summaries to help me remember why these projects are in my bookmarks. In no particular order:

Nanoc

Nanoc’s website describes it as “a tool that runs on your local computer and ‘compiles’ documents written in HTML, Markdown, Textile, Haml, etc. into a static web site, ready for uploading to any web server.” Basically, it takes your dynamic Ruby code and turns it into static HTML which you can then upload to your server, meaning you don’t necessarily need Ruby installed on your server. Of course, this depends on what your site actually needs to do. But I could see this as a perfect fit for a Blog, for which you write posts on your local machine and deploy. Of course you’d need to implement comments with a third-party javascript widget like Disqus, but that’s just one example.

Mongoid

Mongoid is a Ruby ODM framework for mapping your Ruby application to use MongoDB for object storage. If you haven’t checked out MongoDB as an alternative to using MySQL for your storage needs, it’s worth a look. You may not even realize you have different needs until you discover there’s a database out there to fit those needs. For another cool Database-Ruby integration alternative, see Friendly, a gem that makes MySQL look like a document-store to your application.

(more…)



Entries (RSS) and Comments (RSS)