Rails and Github: Some Gotchas

I am working on a Rails3 application, and learned some interesting gotchas today.


  1. It was good to be reminded that when you create associations, you don’t create the foreign keys automatically – you have to figure out how to make the corresponding changes to the database yourself.
  2. You can’t call a model asset. Turns out Rails(3) has already decided to use that word to describe where it puts stylesheets and JavaScript files, so calling /assets/1 gets Rails very confused – it first attempt to find a file called “1” in the assets directory.
  3. has_belong_to_many, aka “HABTM,” is “deprecated” in Rails3, in the sense that most people will probably start with a HABTM but use it for a complex model where they add additional attributes to decorate each element (edge) in the many-to-many graph. So for example if we assign categories to articles, we might additionally atach a timestamp to each category assignment, which would be a new attribute.

Git and Github

  1. Once you’ve made your first commit, all your files are essentially part of your versioning system. If you are going to remove a file, do so via the git rm command. Otherwise, you might your app behaving differently in your development and production environments.
  2. If you use the https URI for your Github repo (like, https://github.com/siruguri/rails_test), you can’t use SSH keys. If you want to do that, you have to use the http version, like so:
  3. git remote set-url <your Github remote name> git@github.com:siruguri/Categorizer

I am sure I’ll learn more as I go along!


Using PostgreSQL on Rails 3: A Tutorial

When you start using Rails, if you, like me, just use things the way they come out of the box, you were probably using SQLite3 as your default database. Your first inkling that this might not be sufficient will come when you try to push your Rails app to Heroku’s servers (“dynos.”) Heroku wants you to use PostgreSQL instead. Continue reading “Using PostgreSQL on Rails 3: A Tutorial”

Heroku and Public Keys: The Full Monty

When you first install the Heroku Toolbelt on your machine, there’s a good chance you will run into a problem with pushing your code via git to the Heroku remote. The common issue is an error message that looks something like this:

Permission denied (publickey).
fatal: Could not read from remote repository.

What you are seeing here is a problem with how your private/public key pairs are configured between your computer and the Heroku server. If you already know what public/private key pairs are, you can skip ahead to the explanation of how to fix this. Continue reading “Heroku and Public Keys: The Full Monty”

Ruby and Rails on Mountain Lion: Having Problems?

I started following the remarkable guide over on Created By Pete, but ran into some problems.

When you install Ruby via rbenv, it needs OpenSSL, and it appears that you need to install the version that Homebrew gives you:

brew install openssl

The installation notes that this version might conflict with the version that’s already installed with OSX: Continue reading “Ruby and Rails on Mountain Lion: Having Problems?”

Adding Custom Styles via the WordPress Visual Editor

Specifically, this is about adding the ability to select pieces of text inside your tinyMCE editor, and having a dropdown of styles to choose from that you can apply to that text.

You need to do two things –

  1. Edit your theme’s style, which you can do from the WordPress dashboard, via Appearance → Edit CSS. Add a style element that looks something like .classname {font-size: 1em}.
  2. This is the tricky part – you have to edit code now. You need to tell the editor to load a drop down called Styles, which will have the styles you want to be able to apply. Look at how it’s done here – the code is explained fairly well.

Continue reading “Adding Custom Styles via the WordPress Visual Editor”