Getting started with learning the Rails source [closed]
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this questionI've been using Ruby on Rails for many开发者_开发知识库 projects lately, and I thought it would be interesting to take a look at the Rails source and really see how things operate underneath. I think it'd be a great learning experience and would probably enhance the way I code Rails apps all the more.
Does anyone have any tips on how to get started? And where within the Rails source does an application begin to be executed? Perhaps if I started there, I could see how everything is loaded and works in general.
I think it'd be a great learning experience and would probably enhance the way I code Rails apps all the more.
This is a great idea!
The first place you should start from is the Rails source on GitHub (here the branch 2.3). If you are using Rails, you are probably familiar with the fact that Rails itself is composed by a few different Gems: ActiveRecord, ActiveSupport, ...
Jumping immediately into the code cannot be that simple. I would suggest you two alternative ways to start digging into Rails codebase:
take the habit, any time you use a method, an helper or a Rails command to jump to lookup the method in the source code and read it. Try to understand its context, how it works and which methods/libraries it uses. Then, each time the method A uses a method B, start to walk back and lookup method B. Set a limit to the number of reverse lookup, for example 2 upper levels so that you won't end up looking up the entire framework starting from the
link_to
helper.instead of starting from the top of the repository, choose the library you are most familiar with. If you don't have any preference, start from ActiveSupport. ActiveSupport is the Rails toolkit. It provides tons of extensions you can use in your Rails code and even in your Ruby programs.
It will take a while before you'll be able to put together all the information and understand how a single Rails application works, but it is definitely worth the effort.
As a side note, a few month ago I started a series called Inside Ruby on Rails. You might want to give it a look.
There is a guide about the Rails (3.0) initialization process: http://ryanbigg.com/guides/initialization.html
I am very late to the party. If you are interested in ActionDispatch (routing request to controller), the documentation "Rails on Rack" is a good starting point.
http://guides.rubyonrails.org/rails_on_rack.html
for current master branch, you need edge guide
http://edgeguides.rubyonrails.org/rails_on_rack.html
The article helps you understand relationship between rails and rack. Once you understand rack, you can figure out the entry point of a request to rails framework.(Rails implementation of rack app interface)
You can follow the entry point and go all the way up to a controller. That is what I did.
how about...
- guides.rubyonrails.org
- railscasts.com
精彩评论