简体   繁体   English

需要帮助理解 Ruby on Rails controller 和 model inheritance 的语法

[英]Need help understanding syntax of Ruby on Rails controller and model inheritance

So far when learning Ruby and Ruby on Rails I keep encountering the syntax到目前为止,在 Rails 上学习 Ruby 和 Ruby 时,我一直遇到语法

ActionController::Base

And have never clarified exactly what it means.并且从未明确说明它的确切含义。 Why the:: instead of say, a slash?为什么 :: 而不是斜线? Wouldn't ActionController/Base be more specific? ActionController/Base 不会更具体吗?

For example, while using the Globalize3 gem I added to my model the line例如,在使用 Globalize3 gem 时,我将以下行添加到我的 model

class About < ActiveRecord::Base
  translates :message
end

I get the generated model named MonthlyPost::Translation, but that doesn't explain much.我得到名为 MonthlyPost::Translation 的生成的 model,但这并不能解释太多。 Where exactly are these stored, and what does the:: mean?这些到底存储在哪里,:: 是什么意思? Any thoughts would be wonderful.任何想法都会很棒。 Thanks.谢谢。

ActionController::Base means find the class Base in the module ActionController. ActionController::Base 表示在模块ActionController中找到class Base。

It's a way of organising your classes, and also to avoid conflicts with classes made by others.这是一种组织课程的方式,也是为了避免与其他人制作的课程发生冲突。

Here is a good article explaining how to use Modules for namespaces. 是一篇很好的文章,解释了如何将模块用于命名空间。

Rails is ruby. Learn ruby and your questions will be answered. Rails是ruby。学习ruby ,你的问题会得到解答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM