Comodo Enterprise EliteSSL on Heroku

I couldn’t find any documentation on the web that directly covers getting a Comodo Enterprise EliteSSL working on Heroku, so here’s a quick guide.

After ordering your SSL cert, generating your CSR (guide here), and submitting it to Comodo, you’ll eventually receive your certificate after all the validation processes (listing in Yellow Pages, automated callback, etc.) has gone through – www_yoursite_com.crt

Now, you need to create a certificate chain to get it working on Heroku. Just adding your certificate you received won’t throw any errors, but it will say SSL certificate is self signed and browsers will complainTo create the certificate chain, you need Root and Intermediate certificates from Comodo. The download page is here. To save you a bit of time, download the Root certificate here and Intermediate certificate here. Once you’ve downloaded those certificates, you should have 3 files to work with: www_yourdomain_com.crtCOMODOHigh-AssuranceSecureServerCA.crt and AddTrustExternalCARoot.crt

To create a chain, simply cat them all into one file:

cat www_yourdomain_com.crt COMODOHigh-AssuranceSecureServerCA.crt AddTrustExternalCARoot.crt > certificate_chain.pem

You should then be able to add or update your certificate on Heroku (I’m assuming you already have your Heroku Toolbelt and account set up on your dev machine.)

heroku certs:update certificate_chain.crt your_private_key.key 

The .key file is the file you generated when you generated your CSR. Hope this saves somebody some headaches.

Ps. If you’re adding a Comodo EV certificate, the process is more or less the same – check out this informative blogpost.

Formtastic Bootstrap and country-select Gem

The Formtastic Bootstrap gem doesn’t support the country-select gem, which provides an easy way to generate a list of countries with formtastic, ie.

<%= f.input :home, :as => :country %>

There is a pull request on GitHub to fix, but it’s yet to be merged. In the meantime, this can easily be added to the gem through monkey patching. To do this, create a file (any descriptive filename will do) in your initializers directory with the content of the pull request.

#file: config/initializers/formtastic_bootstrap_patch.rb

module FormtasticBootstrap
  module Inputs
    class CountryInput < Formtastic::Inputs::CountryInput
      include Base

      def to_html
        generic_input_wrapping do
          builder.country_select(method, priority_countries, input_options, input_html_options)
        end
      end

    end
  end
end

You should now be able to use the :country input type in formtastic-bootstrap:

<%= f.input :home, :as => :country %>

UPDATE:

To make it work with the newest version of Formtastic (as of 2012-09), add the following code into formtastic_bootstrap_patch.rb, instead of the code shown above.

#file: config/initializers/formtastic_bootstrap_patch.rb

module FormtasticBootstrap
  module Inputs
    class CountryInput < Formtastic::Inputs::CountryInput
      include Base

      def to_html
        bootstrap_wrapping do
          builder.country_select(method, priority_countries, input_options, input_html_options)
        end
      end

    end
  end
end

Customizing resource before saving in ActiveAdmin

The ActiveAdmin gem for Ruby on Rails is great to use if you don’t plan on customizing it too much. As a good friend of mine said, it gives you 99% for free, but to get it to do that 1% that you need ends up costing you more than the 99% you got for free in the first place. I wanted to simply customize the resource before it got saved – not that simple, it seems.

I’ve given up with ActiveAdmin on previous project I did and ended up writing my own admin interface and using Bootstrap for the interface. I’m currently in the early stages of another project which may not need to level of customizing as the previous project, so I hope we won’t need any functionality that would require severe hacking of ActiveAdmin at some point.

Anyway, I’m using the awesome Easy Roles gem by Platform45 in the project and I wanted the users created in ActiveAdmin to automatically have the “admin” role added to their roles. The ActiveAdmin documentation again let me down and after some heavy googling and going through the source I figured it out. This is how I did it:

# app/admin/users.rb

ActiveAdmin.register User do
  controller do
    def create
      create! do |format|
        format.html {
          # add default role of admin for now
          resource.add_role 'admin'
          resource.save
        }
        redirect_to '/admin/users'
      end
    end
  end
end

Leave a comment if this saved you a few gray hairs.

Superfish Menu Fadeout

I use the Thematic framework for all the WordPress themes I develop. It ships with Superfish by default to handle the menus. Only issue with Superfish is that it doesn’t fade out menus, which looks a bit wonky. I’ve done a search or two and couldn’t find anything on Google that was newer that 2008 or didn’t 404. I made a quick hack to the hideSuperfishUl function in superfish.js to fade out the submenus. This hasn’t been tested on submenus of submenus, but seems to work fine on single tier menus.

        hideSuperfishUl: function() {
            var e = a.op,
            d = (e.retainPath === true) ? e.$path: "";
            e.retainPath = false;
            var c = b(["li.", e.hoverClass].join(""), this).add(this).not(d).find(">ul").fadeOut('fast',function(){
				jQuery(this).removeClass(e.hoverClass)
			});
            e.onHide.call(c);
            return this
        },

Just replace that part of the file, and it should work.

Easily port an existing database to Rails

I’m busy porting Moo Invoicing from CodeIgniter to Ruby on Rails, and I’ve come to the point where I need to somehow get the existing MySQL database into the new PostGres database, along with the differing schema. Initially I thought the best way would be to connect to the existing MySQL database from Rails, but I couldn’t find enough information on how to do this. I then settled for an easier way – Convert the MySQL database dump to YAML, load it up in a Rails controller and do everything from there. As of writing, I’ve not yet done what I’m planning to do, but it should go something like this:

1 – Dump the database and convert it to YAML using this PHP library by Jonathan Franzone.

2 – In your Rails controller, open the YAML file:

oldDatabase = YAML.load(File.open("pathtofile.yml"))

3 – And bam, you have an object of your whole database that you can iterate through and create new rows from through Active Record!

oldDatabase.clients.each do |client|
    Client.create(:name => client.name)
end

Now, to apply my theory and hope it works. :D

Ruby on Rails :resources routed to different controller

A bit of background info: I’m busy porting Moo Invoicing to Rails as it’s just become too cumbersome to add features to and update in it’s current state. It’s written in CodeIgniter, but the time you save writing something in Rails as compared to your average PHP framework is more than noticeable.

Now, in Moo Invoicing you have invoices and quotes. They’re effectively the same thing, but with some minor differences (due date, payments, etc.) So, instead of having a heap of duplicate code, it makes sense to use the same controllers, models and views for both quotes and invoices. I did pretty much the same thing in CodeIgniter, but rails does much more magic in the background, so to hack it to do your bidding is usually a bad idea and can cause you to loose quite a few “features” the framework provides. Also, being new with Rails, you frequently come to times where you think that what you’re trying to do will be “too advanced” for the framework to handle, and you’ll need to do some actual coding, and more frequently you realize that you’re wrong. Most of the time, the Rails guys have a SUPER easy way out. This is one of those cases – it just wasn’t in any of the Rails guides. Continue reading

Getting ImageMagick to work with Lion and ZSH

Don’t really know if this issue is specific to Lion and ZSH, but upon extracting the ImageMagick binary package (from here) to /usr/local/ on Lion, I couldn’t get it to work as per the instructions on the ImageMagick site. I would just download it or use the Rails gem (rmagick), but since I installed Lion, make doesn’t work any longer and since it’s nearing the end of the month I can’t stand off the bandwidth for the xcode4 download. Continue reading

My comfort zone

I today realized that I’ve slipped into a comfort zone – this is bad thing. Comfort zones hinder learning and personal development. Falling into a comfort zone can kill you and turn you into a hypothetical zombie. I’ve moved into a house and got myself a Land Rover and I’m living a comfortable lifestyle – I generally have everything I want and have wanted for the past couple of years. What now? Now I’m bored. Continue reading

Facebook conversion tracking with Contact Form 7

I was recently asked to add Facebook ad tracking code to one of my WordPress sites which uses the excellent Contact Form 7 plug-in. Doing a quick Google search to find out if there was a best-practice way of doing this, I didn’t come up with anything. Thus, if you’re wondering how to track your facebook ads on your WordPress site using Contact Form 7, this quick tutorial should help you out! Continue reading