views:

61

answers:

2

As a Ruby/Rails non-pro, I often want to check out the code for a rails method to see how it's implemented...

For example, I was using "form_for", and I wanted to check out the code to see how it works. The slightly lame way I did this was to just google "rails form_for" which takes me to http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html, where I can view the source for form_for.

How do rails/ruby pro's accomplish a similar task? Is there a simple way (without using IDEs) that you can quickly dig this out? Or is it a case of over time learning where stuff is located and find/grep-ing it?

Cheers

+1  A: 

I clone the rails repository

git clone git://github.com/rails/rails.git

after I grep on it

git grep 'form_for'

After my Vim editor help my with Ctags to navigate on source code.

If you want some example of code using you can see test unit.

shingara
you can also generate a tag file from your gems. I use rtags and this bash command to index the gems of my Gemfile + the current project + rails: rtags --vi -R . `ruby -e 'dirs=%x(gem dependency rails).map{|l| %x(gem which #{$1}) if l.match(/^\s+(\w+)/)}; dirs+= %x(rake gems).map{|l| %x(gem which #{$2}) if l.match(/\[(I|F|R)\] (\w+)/)}; puts dirs.uniq.compact.map{|d| File.dirname d}.join(" ")'`
hellvinz
arg comments have screwed the command, the grey area should be surrounded by back ticks
hellvinz
add your trick on answer . It's really relevant.
shingara
Didn't know about "git grep", that's pretty useful :)
Matt Roberts
A: 

I prefer http://railsapi.com/ both local and remote. Quick search, nice design and magic Show on Github link

c0r0ner
Nice site. I think for pure ease this wins because it requires the smallest amount of brain effort :)
Matt Roberts