I am working on a Rails3 application, and learned some interesting gotchas today.
Rails
- 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.
- 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.
- 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
- 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.
- 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:
git remote set-url <your Github remote name> git@github.com:siruguri/Categorizer
I am sure I’ll learn more as I go along!