Rails 3 已弃用的方法和 API

发布于 2024-09-17 23:34:17 字数 56 浏览 4 评论 0原文

在哪里可以找到已弃用的方法、API 等的列表,以便从 Rails 2.x 升级到 Rails 3?

Where can one find a list of deprecated methods, APIs, etc, in order to upgrade from Rails 2.x to Rails 3?

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

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

发布评论

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

评论(6

山色无中 2024-09-24 23:34:17

Rails 3 发行说明 有很多有用的信息:

Railties 现已弃用:

  • RAILS_ROOT 转而使用 Rails。 root,
  • RAILS_ENV 支持 Rails.env,
  • RAILS_DEFAULT_LOGGER 支持 Rails.logger。

ActionController:

  • cookie_verifier_secret 已被弃用,现在已被分配
    通过 Rails.application.config.cookie_secret 并移至其自己的文件中:
    配置/初始化程序/cookie_verification_secret.rb。
  • filter_parameter_logging 已弃用,取而代之
    config.filter_parameters << :密码。

Active Record 类中的ActiveRecordnamed_scope

  • 已被弃用,并已重命名为 justscope。
  • save(false) 已弃用,转而使用 save(:validate => false)。
  • model.errors.on 已弃用,取而代之的是 model.errors[]
  • ActiveRecord::Base.colorize_logging 和 config.active_record.colorize_logging 已弃用,取而代之的是 Rails::LogSubscriber.colorize_logging 或 config.colorize_logging

ActionMailer

  • :charset, :content_type, : mime_version、:implicit_parts_order 均已弃用,取而代之的是 ActionMailer.default :key =>值样式声明。
  • Mailer 动态 create_method_name 和 Deliver_method_name 已弃用,只需调用 method_name 现在返回 Mail::Message 对象。
  • ActionMailer.deliver(message) 已弃用,只需调用 message.deliver 即可。
  • template_root 已弃用,将选项从邮件生成块内的 format.mime_type 方法传递给 proc 内的渲染调用
  • 定义实例变量的 body 方法已弃用(body {:ivar => value}),只需在中声明实例变量直接使用该方法,它们将在视图中可用。
  • 不推荐使用应用程序/模型中的邮件程序,请改用应用程序/邮件程序。

The Rails 3 release notes have lots of good information:

Railties now deprecates:

  • RAILS_ROOT in favor of Rails.root,
  • RAILS_ENV in favor of Rails.env, and
  • RAILS_DEFAULT_LOGGER in favor of Rails.logger.

ActionController:

  • The cookie_verifier_secret has been deprecated and now instead it is assigned
    through Rails.application.config.cookie_secret and moved into its own file:
    config/initializers/cookie_verification_secret.rb.
  • filter_parameter_logging is deprecated in favor of
    config.filter_parameters << :password.

ActiveRecord

  • named_scope in an Active Record class is deprecated and has been renamed to just scope.
  • save(false) is deprecated, in favor of save(:validate => false).
  • model.errors.on is deprecated in favor of model.errors[]
  • ActiveRecord::Base.colorize_logging and config.active_record.colorize_logging are deprecated in favor of Rails::LogSubscriber.colorize_logging or config.colorize_logging

ActionMailer

  • :charset, :content_type, :mime_version, :implicit_parts_order are all deprecated in favor of ActionMailer.default :key => value style declarations.
  • Mailer dynamic create_method_name and deliver_method_name are deprecated, just call method_name which now returns a Mail::Message object.
  • ActionMailer.deliver(message) is deprecated, just call message.deliver.
  • template_root is deprecated, pass options to a render call inside a proc from the format.mime_type method inside the mail generation block
  • The body method to define instance variables is deprecated (body {:ivar => value}), just declare instance variables in the method directly and they will be available in the view.
  • Mailers being in app/models is deprecated, use app/mailers instead.
末蓝 2024-09-24 23:34:17

我认为您不会找到详尽的折旧列表,因为这实际上取决于您要升级的 Rails 版本。例如,Rails 2.3.9(刚刚发布)比之前的版本增加了额外的折旧。

Rails 升级手册(如上所述)是一个很棒的工具,包含 12 页的折旧警告以及如何修复他们。我认为它们不会在这里发布,因为你只需花 9 美元下载 pdf 即可获得列表。附带的教程和其他信息使其非常值得。这是给我的。

如果您不想为优质信息付费,只需针对您的特定应用程序运行rails_upgrade 插件即可。有关该插件如何使用的更多信息,请访问 rails 升级插件 github 页面。

I don't think you'll find an exhaustive list of depreciations because it really depends on what version of rails you are upgrading from. For instance, Rails 2.3.9 (just released) added additional depreciations over the previous release.

The Rails Upgrade Handbook (as mentioned above) is a great tool and contains 12 pages of depreciation warnings and how to fix them. I don't think they'll be published here because you should just drop the $9 and download the pdf to get the list. The included tutorials and other information makes it well worth it. It was for me.

If you don't want to pay for good information then just run the rails_upgrade plugin for your specific application. More information on how the plugin is on the rails upgrade plugin github page.

盛夏已如深秋| 2024-09-24 23:34:17

检查单个应用程序细节的一个好方法是在其上运行 rails_upgrade 插件(您可以在 GitHub 上找到它),它将输出弃用通知和建议的列表

一些有用的信息是这篇博文也总结了: http:// www.simonecarletti.com/blog/2010/07/the-way-to-rails-3/

另外,Railscasts 有很多关于 API 各个变化方面的电影。访问 Railscasts.com 并浏览 rails3 标签下归档的电影。

A good way of checking the specifics about an individual app would be to run the rails_upgrade plugin on it (you can find it at GitHub), it will output a list of deprecation notices and recommendations

Some useful info is also summarised in this blog post: http://www.simonecarletti.com/blog/2010/07/the-way-to-rails-3/

Additionally Railscasts has a bunch of movies on various changed aspects of the API. Go to Railscasts.com and browse the movies filed under the rails3 tag.

↘紸啶 2024-09-24 23:34:17

我发现购买 http://www.railsupgradehandbook.com/ 非常划算

I found it to be a great value to buy http://www.railsupgradehandbook.com/

寄与心 2024-09-24 23:34:17

另一个弃用活动记录的地方是这里(http://m.onkey.org/active-record-query-interface)。

如果觉得有用就回复。

Another place to have deprecation's for active record is here (http://m.onkey.org/active-record-query-interface).

Reply if found useful.

做个少女永远怀春 2024-09-24 23:34:17

如何在没有 Rails 的情况下禁用 ActiveRecord 中的着色日志记录? AR 现在不再是保持解耦、独立的 ORM,而是与 Rails 框架紧密绑定。

将 ActiveRecord::Base.colorize_logging 移动到 Rails::LogSubscriber.colorize_logging 只是糟糕的设计和错误的方向,不是吗?

How to disable colorize logging in ActiveRecord without Rails? Instead of keeping AR decoupled, independent ORM, it is now tightly bound to Rails framework.

Moving ActiveRecord::Base.colorize_logging to Rails::LogSubscriber.colorize_logging was just bad design and the wrong direction, wasn't was?

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