开始学习 Rails 源码

发布于 2024-08-29 23:41:09 字数 1436 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

暮色兮凉城 2024-09-05 23:41:09

我认为这是一次很好的学习
经验并可能会提高
我编码 Rails 应用程序的方式
更多。

这是个好主意!

您应该从 GitHub 上的 Rails 源代码开始(这里是 分支 2.3)。如果您使用 Rails,您可能熟悉 Rails 本身由几个不同的 Gem 组成的事实: ActiveRecordActiveSupport、...

跳转立即进入代码不可能那么简单。我建议您使用两种替代方法来开始深入研究 Rails 代码库:

  • 养成习惯,任何时候您使用方法、帮助程序或 Rails 命令时都会跳转到源代码中查找该方法并阅读它。尝试了解它的上下文、它是如何工作的以及它使用哪些方法/库。然后,每次方法A使用方法B时,开始回溯并查找方法B。设置反向查找的次数限制,例如2个上层,这样您就不会从头开始查找整个框架来自 link_to 帮助器。

  • 不要从存储库顶部开始,而是选择您最熟悉的库。如果您没有任何偏好,请从 ActiveSupport 开始。 ActiveSupport 是 Rails 工具包。它提供了大量的扩展,您可以在 Rails 代码甚至 Ruby 程序中使用。

您需要一段时间才能将所有信息放在一起并了解单个 Rails 应用程序的工作原理,但这绝对值得付出努力。

作为旁注,几个月前我开始了一个名为 Ruby on Rails 内部。您可能想看一下。

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.

猫七 2024-09-05 23:41:09

有一个关于 Rails (3.0) 初始化过程的指南: http://ryanbigg.com/guides/initialization .html

There is a guide about the Rails (3.0) initialization process: http://ryanbigg.com/guides/initialization.html

兮颜 2024-09-05 23:41:09

我参加聚会已经很晚了。
如果您对 ActionDispatch(将请求路由到控制器)感兴趣,文档“Rails on Rack”是一个很好的起点。

http://guides.rubyonrails.org/rails_on_rack.html

对于当前的master分支,你需要edge指南

http://edgeguides.rubyonrails.org/rails_on_rack.html

本文帮助您了解之间的关系导轨和机架。一旦你了解了rack,你就可以找出对rails框架的请求的入口点。(rack应用程序接口的Rails实现)

你可以沿着入口点一直到达控制器。我就是这么做的。

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.

浪漫人生路 2024-09-05 23:41:09

样...

  • guides.rubyonrails.orgrailscasts.com
  • 怎么

how about...

  • guides.rubyonrails.org
  • railscasts.com
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文