- 浏览: 77283 次
- 性别:
- 来自: 地球
最近访客 更多访客>>
文章分类
最新评论
-
zhou1986lin:
[flash=200,200][b]引用[size=x-sma ...
新浪编辑器 -
vb2005xu:
晕 想不出来 为什么要实现 什么什么语言的 版本的好处
不都是 ...
新浪编辑器 -
minma_yuyang:
还不错,借鉴了。
Code style -
天机老人:
谢谢啊,这文章不错!
Sphinx -
suncanoe:
<iframe id="myEditor&qu ...
新浪编辑器
Ruby on Rails 2.2 发行笔记
1. Infrastructure
Rails 2.2 is a significant release for the infrastructure that keeps Rails humming along and connected to the rest of the world.
1.1. Internationalization国际化
Rails 2.2 supplies an easy system for internationalization (or i18n, for those of you tired of typing).
Lead Contributors主要贡献团队: Rails i18 Team
More information :
Official Rails i18 website
Finally. Ruby on Rails gets internationalized
Localizing Rails : Demo application
1.2. Compatibility兼容 with Ruby 1.9 and JRuby
Along with thread safety, a lot of work has been done to make Rails work well with JRuby and the upcoming Ruby 1.9. With Ruby 1.9 being a moving target, running edge Rails on edge Ruby is still a hit-or-miss proposition, but Rails is ready to make the transition to Ruby 1.9 when the latter is released.
3. Better integration with HTTP : Out of the box ETag support
Supporting the etag and last modified timestamp in HTTP headers means that Rails can now send back an empty response if it gets a request for a resource that hasn't been modified lately. This allows you to check whether a response needs to be sent at all.
class ArticlesController < ApplicationController
def show_with_respond_to_block
@article = Article.find(params[:id])
# If the request sends headers that differs from the options provided to stale?, then
# the request is indeed stale and the respond_to block is triggered (and the options
# to the stale? call is set on the response).
#
# If the request headers match, then the request is fresh and the respond_to block is
# not triggered. Instead the default render will occur, which will check the last-modified
# and etag headers and conclude that it only needs to send a "304 Not Modified" instead
# of rendering the template.
if stale?(:last_modified => @article.published_at.utc, :etag => @article)
respond_to do |wants|
# normal response processing
end
end
end
def show_with_implied_render
@article = Article.find(params[:id])
# Sets the response headers and checks them against the request, if the request is stale
# (i.e. no match of either etag or last-modified), then the default render of the template happens.
# If the request is fresh, then the default render will return a "304 Not Modified"
# instead of rendering the template.
fresh_when(:last_modified => @article.published_at.utc, :etag => @article)
end
end
4. Thread Safety
The work done to make Rails thread-safe is rolling out in Rails 2.2. Depending on your web server infrastructure, this means you can handle more requests with fewer copies of Rails in memory, leading to better server performance and higher utilization of multiple cores.意味着在内存里更少的RAILS拷贝可以处理更多的请求,导致更好的服务性能和更高的多核利用率。
To enable multithreaded dispatching in production mode of your application, add the following line in your config/environments/production.rb:
添加
config.threadsafe!
More information :
Thread safety for your Rails
Thread safety project announcement
Q/A: What Thread-safe Rails Means
5. Active Record
There are two big additions to talk about here: transactional migrations 迁移的事务性and pooled database transactions数据库连接池. There's also a new (and cleaner) syntax for join table conditions, as well as a number of smaller improvements.
5.1. Transactional Migrations
Historically, multiple-step Rails migrations have been a source of trouble. If something went wrong during a migration, everything before the error changed the database and everything after the error wasn't applied. Also, the migration version was stored as having been executed, which means that it couldn't be simply rerun by rake db:migrate:redo after you fix the problem. Transactional migrations change this by wrapping migration steps in a DDL transaction, so that if any of them fail, the entire migration is undone. In Rails 2.2, transactional migrations are supported on PostgreSQL out of the box.
现在PostgreSQL支持,以后会扩展其他数据库。 The code is extensible to other database types in the future - and IBM has already extended it to support the DB2 adapter.
Lead Contributor: Adam Wiggins
More information:
DDL Transactions
A major milestone for DB2 on Rails
5.2. Connection Pooling
Connection pooling lets Rails distribute database requests across a pool of database connections that will grow to a maximum size (by default 5, but you can add a pool key to your database.yml to adjust this). This helps remove bottlenecks in applications that support many concurrent users. There's also a wait_timeout that defaults to 5 seconds before giving up. ActiveRecord::Base.connection_pool gives you direct access to the pool if you need it.
development:
adapter: mysql
username: root
database: sample_development
pool: 10
wait_timeout: 10
Lead Contributor: Nick Sieger
More information:
What's New in Edge Rails: Connection Pools
5.3. Hashes for Join Table Conditions
You can now specify conditions on join tables using a hash. This is a big help if you need to query across complex joins.
class Photo < ActiveRecord::Base
belongs_to :product
end
class Product < ActiveRecord::Base
has_many :photos
end
# Get all products with copyright-free photos:
Product.all(:joins => :photos, :conditions => { :photos => { :copyright => false }})
在conditions里使用hashes来指定查询条件
More information:
What's New in Edge Rails: Easy Join Table Conditions
5.4. New Dynamic Finders
Two new sets of methods have been added to Active Record's dynamic finders family.
5.4.1. find_last_by_<attribute>
The find_last_by_<attribute> method is equivalent to Model.last(:conditions ⇒ {:attribute ⇒ value})
# Get the last user who signed up from London
User.find_last_by_city('London')
Lead Contributor: Emilio Tagua
5.4.2. find_by_<attribute>!
The new bang! version of find_by_<attribute>! is equivalent to Model.first(:conditions ⇒ {:attribute ⇒ value}) || raise ActiveRecord::RecordNotFound Instead of returning nil if it can't find a matching record, this method will raise an exception if it cannot find a match.
# Raise ActiveRecord::RecordNotFound exception if 'Moby' hasn't signed up yet!
User.find_by_name!('Moby')
Lead Contributor: Josh Susser
5.5. Associations Respect Private/Protected Scope关联开始增加对Private/Protected的支持(不能通过关联调用对方的私有方法)
Active Record association proxies now respect the scope of methods on the proxied object. Previously (given User has_one :account) @user.account.private_method would call the private method on the associated Account object. That fails in Rails 2.2; if you need this functionality, you should use @user.account.send(:private_method) (or make the method public instead of private or protected). Please note that if you're overriding method_missing, you should also override respond_to to match the behavior in order for associations to function normally.
Lead Contributor: Adam Milligan
More information:
Rails 2.2 Change: Private Methods on Association Proxies are Private
5.6. Other ActiveRecord Changes
rake db:migrate:redo now accepts an optional VERSION to target that specific migration to redo
Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp.
Counter cache columns (for associations declared with :counter_cache ⇒ true) do not need to be initialized to zero any longer.
ActiveRecord::Base.human_name for an internationalization-aware humane translation of model names
6. Action Controller
On the controller side, there are several changes that will help tidy up your routes. There are also some internal changes in the routing engine to lower memory usage on complex applications.
6.1. Shallow Route Nesting浅路由
Shallow route nesting provides a solution to the well-known difficulty of using deeply-nested resources. With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with.
map.resources :publishers, :shallow => true do |publisher|
publisher.resources :magazines do |magazine|
magazine.resources :photos
end
end
This will enable recognition of (among others) these routes:
/publishers/1 ==> publisher_path(1)
/publishers/1/magazines ==> publisher_magazines_path(1)
/magazines/2 ==> magazine_path(2)
/magazines/2/photos ==> magazines_photos_path(2)
/photos/3 ==> photo_path(3)
Lead Contributor: S. Brent Faulkner
More information:
Rails Routing from the Outside In
What's New in Edge Rails: Shallow Routes
1. Infrastructure
Rails 2.2 is a significant release for the infrastructure that keeps Rails humming along and connected to the rest of the world.
1.1. Internationalization国际化
Rails 2.2 supplies an easy system for internationalization (or i18n, for those of you tired of typing).
Lead Contributors主要贡献团队: Rails i18 Team
More information :
Official Rails i18 website
Finally. Ruby on Rails gets internationalized
Localizing Rails : Demo application
1.2. Compatibility兼容 with Ruby 1.9 and JRuby
Along with thread safety, a lot of work has been done to make Rails work well with JRuby and the upcoming Ruby 1.9. With Ruby 1.9 being a moving target, running edge Rails on edge Ruby is still a hit-or-miss proposition, but Rails is ready to make the transition to Ruby 1.9 when the latter is released.
3. Better integration with HTTP : Out of the box ETag support
Supporting the etag and last modified timestamp in HTTP headers means that Rails can now send back an empty response if it gets a request for a resource that hasn't been modified lately. This allows you to check whether a response needs to be sent at all.
class ArticlesController < ApplicationController
def show_with_respond_to_block
@article = Article.find(params[:id])
# If the request sends headers that differs from the options provided to stale?, then
# the request is indeed stale and the respond_to block is triggered (and the options
# to the stale? call is set on the response).
#
# If the request headers match, then the request is fresh and the respond_to block is
# not triggered. Instead the default render will occur, which will check the last-modified
# and etag headers and conclude that it only needs to send a "304 Not Modified" instead
# of rendering the template.
if stale?(:last_modified => @article.published_at.utc, :etag => @article)
respond_to do |wants|
# normal response processing
end
end
end
def show_with_implied_render
@article = Article.find(params[:id])
# Sets the response headers and checks them against the request, if the request is stale
# (i.e. no match of either etag or last-modified), then the default render of the template happens.
# If the request is fresh, then the default render will return a "304 Not Modified"
# instead of rendering the template.
fresh_when(:last_modified => @article.published_at.utc, :etag => @article)
end
end
4. Thread Safety
The work done to make Rails thread-safe is rolling out in Rails 2.2. Depending on your web server infrastructure, this means you can handle more requests with fewer copies of Rails in memory, leading to better server performance and higher utilization of multiple cores.意味着在内存里更少的RAILS拷贝可以处理更多的请求,导致更好的服务性能和更高的多核利用率。
To enable multithreaded dispatching in production mode of your application, add the following line in your config/environments/production.rb:
添加
config.threadsafe!
More information :
Thread safety for your Rails
Thread safety project announcement
Q/A: What Thread-safe Rails Means
5. Active Record
There are two big additions to talk about here: transactional migrations 迁移的事务性and pooled database transactions数据库连接池. There's also a new (and cleaner) syntax for join table conditions, as well as a number of smaller improvements.
5.1. Transactional Migrations
Historically, multiple-step Rails migrations have been a source of trouble. If something went wrong during a migration, everything before the error changed the database and everything after the error wasn't applied. Also, the migration version was stored as having been executed, which means that it couldn't be simply rerun by rake db:migrate:redo after you fix the problem. Transactional migrations change this by wrapping migration steps in a DDL transaction, so that if any of them fail, the entire migration is undone. In Rails 2.2, transactional migrations are supported on PostgreSQL out of the box.
现在PostgreSQL支持,以后会扩展其他数据库。 The code is extensible to other database types in the future - and IBM has already extended it to support the DB2 adapter.
Lead Contributor: Adam Wiggins
More information:
DDL Transactions
A major milestone for DB2 on Rails
5.2. Connection Pooling
Connection pooling lets Rails distribute database requests across a pool of database connections that will grow to a maximum size (by default 5, but you can add a pool key to your database.yml to adjust this). This helps remove bottlenecks in applications that support many concurrent users. There's also a wait_timeout that defaults to 5 seconds before giving up. ActiveRecord::Base.connection_pool gives you direct access to the pool if you need it.
development:
adapter: mysql
username: root
database: sample_development
pool: 10
wait_timeout: 10
Lead Contributor: Nick Sieger
More information:
What's New in Edge Rails: Connection Pools
5.3. Hashes for Join Table Conditions
You can now specify conditions on join tables using a hash. This is a big help if you need to query across complex joins.
class Photo < ActiveRecord::Base
belongs_to :product
end
class Product < ActiveRecord::Base
has_many :photos
end
# Get all products with copyright-free photos:
Product.all(:joins => :photos, :conditions => { :photos => { :copyright => false }})
在conditions里使用hashes来指定查询条件
More information:
What's New in Edge Rails: Easy Join Table Conditions
5.4. New Dynamic Finders
Two new sets of methods have been added to Active Record's dynamic finders family.
5.4.1. find_last_by_<attribute>
The find_last_by_<attribute> method is equivalent to Model.last(:conditions ⇒ {:attribute ⇒ value})
# Get the last user who signed up from London
User.find_last_by_city('London')
Lead Contributor: Emilio Tagua
5.4.2. find_by_<attribute>!
The new bang! version of find_by_<attribute>! is equivalent to Model.first(:conditions ⇒ {:attribute ⇒ value}) || raise ActiveRecord::RecordNotFound Instead of returning nil if it can't find a matching record, this method will raise an exception if it cannot find a match.
# Raise ActiveRecord::RecordNotFound exception if 'Moby' hasn't signed up yet!
User.find_by_name!('Moby')
Lead Contributor: Josh Susser
5.5. Associations Respect Private/Protected Scope关联开始增加对Private/Protected的支持(不能通过关联调用对方的私有方法)
Active Record association proxies now respect the scope of methods on the proxied object. Previously (given User has_one :account) @user.account.private_method would call the private method on the associated Account object. That fails in Rails 2.2; if you need this functionality, you should use @user.account.send(:private_method) (or make the method public instead of private or protected). Please note that if you're overriding method_missing, you should also override respond_to to match the behavior in order for associations to function normally.
Lead Contributor: Adam Milligan
More information:
Rails 2.2 Change: Private Methods on Association Proxies are Private
5.6. Other ActiveRecord Changes
rake db:migrate:redo now accepts an optional VERSION to target that specific migration to redo
Set config.active_record.timestamped_migrations = false to have migrations with numeric prefix instead of UTC timestamp.
Counter cache columns (for associations declared with :counter_cache ⇒ true) do not need to be initialized to zero any longer.
ActiveRecord::Base.human_name for an internationalization-aware humane translation of model names
6. Action Controller
On the controller side, there are several changes that will help tidy up your routes. There are also some internal changes in the routing engine to lower memory usage on complex applications.
6.1. Shallow Route Nesting浅路由
Shallow route nesting provides a solution to the well-known difficulty of using deeply-nested resources. With shallow nesting, you need only supply enough information to uniquely identify the resource that you want to work with.
map.resources :publishers, :shallow => true do |publisher|
publisher.resources :magazines do |magazine|
magazine.resources :photos
end
end
This will enable recognition of (among others) these routes:
/publishers/1 ==> publisher_path(1)
/publishers/1/magazines ==> publisher_magazines_path(1)
/magazines/2 ==> magazine_path(2)
/magazines/2/photos ==> magazines_photos_path(2)
/photos/3 ==> photo_path(3)
Lead Contributor: S. Brent Faulkner
More information:
Rails Routing from the Outside In
What's New in Edge Rails: Shallow Routes
发表评论
-
架起自己的blog, 以后我的博客将更新至 http://kunlunblogs.herokuapp.com
2010-03-09 12:11 840博客辗转几个地方, 最终还是去heroku吧 http://k ... -
检查并显示mobile页面
2010-03-05 13:39 802根据user_agent判断是否是手机设备 reque ... -
给任务传递参数
2010-03-05 10:45 953desc 'For test params' task ... -
扩展paperclip 增加watermark
2010-03-05 01:46 12811. /lib/paperclip processors ad ... -
rails read digital photo
2010-03-05 01:28 9241 gem install exifr 2 $ irb -r ... -
rails' cron rufus-scheduler
2010-03-04 15:49 13061 installation sudo gem inst ... -
searchlogic
2010-03-03 14:57 815This plugin help searching. you ... -
capistrano配置
2010-03-02 16:21 1482服务器文件结构 mya ... -
passenger 工具查看内存状态
2010-03-02 15:59 10681. inspect Phusion Passenger’s ... -
passenger apache 设定
2010-03-02 15:56 995sudo vim /etc/apache2/httpd.con ... -
rails plugin-- auto_migrations
2010-03-02 12:09 844一般我们更改表结构的时候,数据会自动清空,挺麻烦的。auto_ ... -
a question
2010-01-28 20:10 832目前,经理想知道从A地址(例如10.1.3.1)到B地址(例如 ... -
在日志中过滤password
2010-01-28 14:00 839在user controller中加入 filter_para ... -
radiantcms
2009-12-02 17:33 742http://radiantcms.org/overview/ ... -
file copy
2009-06-23 14:39 865require 'ftools' namespace :ae ... -
copy files from original dir to other dir
2009-06-23 14:35 739namespace :ae do desc &quo ... -
ActionMailer 发送 email
2009-05-19 18:57 924配置 environment -- development.r ... -
Ruby rake file
2009-05-14 15:20 864task :import_projects => :en ... -
Mini_magick
2009-05-14 13:18 1315MiniMagick中Image对象有一个shave方法,正好 ... -
匹配所有路由
2009-05-14 11:57 623*path hehe
相关推荐
《Ruby on Rails Tutorial》中文版(原书第2版,涵盖 Rails 4) Ruby 是一门很美的计算机语言,其设计原则就是“让编程人员快乐”。David Heinemeier Hansson 就是看重了这一点,才在开发 Rails 框架时选择了 Ruby...
### Ruby on Rails 101:深入理解与实践 #### 引言 《Ruby on Rails 101》是一本介绍Ruby on Rails(简称RoR或ROR)的基础书籍,旨在为初学者提供一个全面而深入的学习框架。本书由Peter Marklund编写,包含了五天...
Ruby on Rails是一款基于Ruby语言的开源Web开发框架,它遵循MVC(模型-视图-控制器)架构模式,简化了Web应用的开发流程。在Linux环境下安装Ruby on Rails需要一系列的依赖包和步骤,本资源包提供了所需的所有组件,...
Ruby on Rails,简称Rails,是基于Ruby编程语言的一个开源Web应用程序框架,它遵循MVC(模型-视图-控制器)架构模式,旨在提高开发效率和代码的可读性。Rails以其“约定优于配置”(Convention over Configuration)...
《Ruby on Rails 3 Tutorial》是一本专门为初学者设计的指南,旨在帮助读者快速掌握Ruby on Rails这一强大的Web开发框架。Ruby on Rails(简称Rails)是基于Ruby语言的一个开源框架,它采用MVC(Model-View-...
《Ruby on Rails for Dummies》是一本专门为初学者设计的Ruby on Rails教程,它旨在帮助新手快速理解并掌握这个强大的Web开发框架。Ruby on Rails(简称Rails)是基于Ruby编程语言构建的一个开源Web应用程序框架,它...
### Ruby on Rails Guides v2 - Ruby on Rails 4.2.5 #### 一、重要概念及基础假设 - **重要概念**:本指南旨在帮助读者深入理解Ruby on Rails(以下简称Rails)4.2.5版本的核心功能与最佳实践。 - **基础假设**:...
本书教您如何使用Ruby on Rails开发和部署真正的,具有工业实力的Web应用程序,Ruby on Rails是为诸如Twitter,Hulu,GitHub和Yellow Pages等顶级网站提供支持的开源Web框架。
Ruby on Rails,简称Rails,是一款基于Ruby语言的开源Web应用框架,它遵循MVC(Model-View-Controller)架构模式,旨在简化Web应用程序的开发。Rails由David Heinemeier Hansson于2004年创建,它提倡“约定优于配置...
《Ruby on Rails入门权威经典》是一本专门为初学者设计的指南,旨在帮助读者全面掌握Ruby on Rails这一强大的Web开发框架。Ruby on Rails(简称Rails)是基于Ruby编程语言的开源框架,以其“DRY(Don't Repeat ...
### Ruby on Rails与Java框架对比分析 #### 一、引言 随着互联网技术的迅猛发展,Web开发领域也迎来了各种各样的开发框架和技术栈。在众多的开发框架中,Ruby on Rails (RoR) 和 Java 的相关框架尤其受到关注。本文...
Ruby on Rails,简称Rails,是基于Ruby语言的一个开源Web应用程序框架,它遵循MVC(Model-View-Controller)架构模式,旨在使Web开发过程更加高效、简洁。本压缩包中的"Ruby on Rails入门经典代码"提供了新手学习...
Ruby On Rails 框架自它提出之日起就受到广泛关注,在“不要重复自己”,“约定优于配置”等思想的指导下,Rails 带给 Web 开发者的是极高的开发效率。 ActiveRecord 的灵活让你再也不用配置繁琐的 Hibernate 即可...
Ruby on Rails,简称Rails,是基于Ruby语言的开源Web应用框架,它遵循MVC(Model-View-Controller)架构模式,旨在使开发过程更加简洁高效。这个“ruby on rails 教程源码”很可能是为了辅助学习者深入理解Rails的...
Ruby on Rails,简称Rails,是由David Heinemeier Hansson基于Ruby语言开发的一个开源Web应用程序框架。这个框架遵循“约定优于配置”(Convention over Configuration)的原则,致力于简化Web应用的开发流程,提高...
Ruby on Rails,简称Rails,是一款基于Ruby语言的开源Web应用框架,它遵循MVC(Model-View-Controller)架构模式,旨在提升开发效率和代码的可读性。Rails以其“约定优于配置”的设计理念,以及“DRY(Don't Repeat ...
Ruby on Rails 4 Tutorial 是一本深受开发者欢迎的书籍,它详细介绍了如何使用Ruby on Rails这一强大的Web开发框架。Ruby on Rails(简称Rails)是基于Ruby语言的开源框架,以其“约定优于配置”(Convention over ...
Ruby on Rails(简称Rails)是一种基于Ruby语言的开源Web应用程序框架,它遵循MVC(Model-View-Controller)架构模式,旨在简化Web开发过程并提高效率。在这个“ruby on rails在线考试系统”中,我们可以探讨以下几...