Ruby on Rails:Rails 3 中有哪些概念会在我开始使用 Rails 4(测试版已发布)时更改或需要完全删除?
还了解到ActiveRecord观察者的用法,已经提取到gem中了。新的 gem 将位于 github.com,rails-observers。
最佳答案
根据发行说明 (http://edgeguides.rubyonrails.org/4_0_release_notes.html):
亮点
首选 Ruby 2.0;需要 1.9.3+
这是不言自明的。
强参数
允许您为来自 Controller 的批量分配指定允许的属性。
在这里阅读更多相关信息:http://blog.remarkablelabs.com/2012/12/strong-parameters-rails-4-countdown-to-2013
涡轮链接
“它不会让浏览器在每次页面更改之间重新编译 JavaScript 和 CSS,而是让当前页面实例保持事件状态,并仅替换头部的正文和标题。”
查看 github 页面:https://github.com/rails/turbolinks
俄罗斯套娃缓存
这是一种缓存技术,您可以在此处阅读更多信息:http://blog.remarkablelabs.com/2012/12/russian-doll-caching-cache-digests-rails-4-countdown-to-2013
主要变化和弃用
提取到 gems 中的特征:
- Hash-based & Dynamic finder methods
- Mass assignment protection in Active Record models
- ActiveRecord::SessionStore
- Active Record Observers
- Active Resource
- Action Caching
- Page Caching
- Sprockets
- Performance tests
如果使用Rails默认测试框架,目录有如下变化:
- 测试/单元 -> 测试/模型
- 测试/单元/助手 -> 测试/助手
- 测试/功能 -> 测试/ Controller
- 测试/功能 -> 测试/邮件
- 测试/集成 -> 测试/验收
供应商插件
已弃用。您在 vendor/plugins 中可能拥有的任何插件都必须作为 gems 安装。
事件记录
以下方法已弃用,需要重写如下:
-
find_all_by_...
可以使用where(...)
重写. -
find_last_by_...
可以使用where(...).last
重写. -
scoped_by_...
可以使用where(...)
重写. -
find_or_initialize_by_...
可以使用where(...).first_or_initialize
重写. -
find_or_create_by_...
可以使用find_or_create_by(...)
重写或where(...).first_or_create
. -
find_or_create_by_...!
可以使用find_or_create_by!(...)
重写或where(...).first_or_create!
.
关于ruby-on-rails - rails 4 中需要的重要 rails 3.2 概念,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15271525/