A good read on table index.
http://www.railway.at/articles/2008/04/24/database-agnostic-database-ignorant
Sometimes, it is easy to forget when someone or something else handles it for you. For instance, ActiveRecords. Rails does not create foreign keys for you. It only creates the primary key. It does not impose constraint on the database level. The association is handled on the application level. So always remember to create an index for your model associations. It could save your database server from working too hard.
Do not name your database column with the name ‘no’.
You’ll get this error when you try to run your test
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ‘false’ in ‘field list’
If you’re someone who has multiple git branches on a project and seem to always do git branch to check which branch you’re in. Then here’s how you can make your bash aware of a git branch.
Well, I’m not sure if this works on others, but it sure does works in my Ubuntu Hardy. Just edit your .bashrc at your home folder.
vim .bashrc
Add the following at the very bottom of your .bashrc
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$(parse_git_branch) $ "
After that, save it and restart your terminal. You should see something like this at your terminal:
fadhli@atlantis:~/projects/crimson_mdec(master) $
I have a branch named biz_idea, so after a git checkout biz_idea
Switched to branch “biz_idea”
fadhli@atlantis:~/projects/crimson_mdec(biz_idea) $
The beauty of git is there is no one true way to do it. Here’s how the Rails Frameworks maintainers uses git.
http://rails.lighthouseapp.com/projects/8994/sending-patches
And here’s a wonderful video from Railscast on how to contribute to Rails.
Forking is to clone an entire remote repository into another
remote repository. Now you have two repositories based around the
same code base. At that one point in time, they have the same set of
files and the same history of changes.
In our case, you’d fork a git repo. Then, you do a git clone of the repo that you’d just forked.
To you, once you’ve forked a repository, then your repository is
your git “origin” and the original repository you forked just
becomes a fork to pull from when you want to synchronise your
repositories. Make sense? Thought so.
At your local machine terminal,
git clone <your_forked_git_repo>
Now, you have your own local repo.
But what if others makes a change to the code? Well, you need to track their changes. Here is how … base on this website.. (http://railsontherun.com/2008/3/3/how-to-use-github-and-submit-a-patch)
Enter the following at your own local repo.
git remote add main_repo <the_git_repo_that_you’d_fork_from>
This will add information in your .git/config of another remote repository that you like to remain updated in your local repo.
Then, the following:
git fetch main_repo
The following output will come out
From <the_git_repo_that_you’d_fork_from>
* [new branch] master -> main_repo/master
Then, do this:
git checkout -b main_repo main_repo/master
The command tells git to create a new branch name main_repo and checkout to that repo.
The following output will come out:
Branch main_repo set up to track remote branch refs/remotes/main_repo/master.
Switched to a new branch “main_repo”
If you do
git branch
You’ll see this:
* main_repo
master
The asterisk shows which branch you’re currently in.
If you do
git branch -r
You’ll see the following
main_repo/master
main_repo/no_signup
origin/HEAD
origin/master
origin/no_signup
The origin is your remote repo, while the main_repo is from the repo that you’ve just forked.
To pull from the main_repo, make sure you’re in the main_repo branch first.
To switch to the main repo branch:
git checkout main_repo
Then pull from the main_repo codes:
git pull main_repo
Then, switch back to your master branch
git checkout master
So to merge the main_repo branch to your master. (Make sure you commit your work first before merging with the main repo.)
git merge main_repo
If there’s conflict, if you’re sure about what’s need to be resolve then code away. Git will tell you which files are in conflict state.
So after you’ve done with your codes. It’s time to push it. Again, make sure you’re in your master branch. Just do:
Then, notify the main_repo maintainer to pull from your repo.
This is one way to work within a team that I know. Maybe in time, I’ll find a better way to work with git much more efficiently.
I had to make sure my git branch is updated with my master.
So at my master branch
git pull master
Next, I switched to my branch named ‘feature_super_tag’.
git checkout feature_super_tag
and then
git rebase master
A good explanation of what a rebase does is from these two blogs:
http://jbowes.dangerouslyinc.com/2007/01/26/git-rebase-keeping-your-branches-current/
http://adam.blog.heroku.com/past/2008/6/30/rebasing_is_editing_commits/
Note: It’s a good policy to never work in your master. Make a branch first for any changes you want to do.
Assume you have a git branch named experimental and you would like to push it to your remote repository.
Then just do
git push origin experimental
Now other people can see the remote branch if they do git branch -r.
Perhaps they should do a git pull first before the git branch -r.
This should come out:
origin/experimental
If they would like to work on that branch then simply
git branch <your_branch_name> origin/experimental
Don’t forget to git checkout <your_branch_name> first.
Pheww.. all test pass after the latest ruby package updates from the ubuntu team.
I was a little worried reading the comments from the official Rails site. From the comments, a lot of people are experiencing problems after using the patch provided by the official Ruby team.
However, today I received an update notification on my Hardy that a package is available with the latest Ruby security updates. So I installed it and no problems accounted so far while testing my Rails2.1 app. Fortunately that the project I’m working on has a good test coverage. (I made sure of it too!)
Last weekend, I finally decided to upgrade my Gutsy to Hardy. After the installation, everything was working fine. The only thing is that I have no Firebug on Firefox3. I tried to install it through it’s website but it said that it’s not compatible with mine.
Googling the net, I found out that it’s a package in the ubuntu repositories. So with a simple
sudo apt-get install firebug
I was
I have only one burning desire
Let me stand next to your fire — Jimi Hendrix
Note: Restart your firefox after installing firebug.
A label method is introduced in Rails 2.1.
The following code:
<% form_for (@post) do |f| %>
<%= f.label :title %>
#Code truncated for clarity
<% end %>
Would generate the following HTML:
<label for="post_title">Title</label>
If your label contains a css class and if you need another name other than the default column name for your label, just do as following:
<%= f.label :title, "Please key in a title", :class => "form_label" %>
The code above will generate the following:
<label for="post_title" class="form_label">Please key in a title</label>