ruby-on-rails – 做什么?

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 做什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些我正在修改的继承代码.但是,我看到一些奇怪的东西(对我来说).

我看到一些像这样的代码

  1. ::User.find_by_email(params[:user][:email]).update_attributes(:mag => 1)

我从未见过这样的东西(我是Ruby on Rails的新手).这是做什么的,为什么我的User.find_by_email(params [:user] [:email]).update_attributes(:mag => 1)不起作用?该错误说明了User常量.

如果有帮助,我正在使用Rails 2.3.5.

解决方法

::是一个范围解析运算符,它实际上意味着“在命名空间中”,所以ActiveRecord :: Base意味着“Base,在ActiveRecord的命名空间中”

在任何名称空间之外解析的常量意味着它听起来完全是什么 – 根本不在任何名称空间中的常量.

它用于代码可能不明确的地方:

  1. module Document
  2. class Table # Represents a data table
  3.  
  4. def setup
  5. Table # Refers to the Document::Table class
  6. ::Table # Refers to the furniture class
  7. end
  8.  
  9. end
  10. end
  11.  
  12. class Table # Represents furniture
  13. end

猜你在找的Ruby相关文章