Rails 3.0 正式版发布了
Rails 3.0 在经过多个测试版后,今天终于迎来的正式版本。
安装方法:gem install rails --version 3.0.0.
Rails 是一个用于开发数据库驱动的网络应用程序的完整框架。Rails基于MVC(模型- 视图- 控制器)设计模式。从视图中的Ajax应用,到控制器中的访问请求和反馈,到封装数据库的模型,Rails 为你提供一个纯Ruby的开发环境。发布网站时,你只需要一个数据库和一个网络服务器即可。
Rails 3.0 主要改进内容:
1. 全新活动记录查询引擎
示例代码:
- users = User.where(:name => "david").limit(20)
- users = users.where("age > 29")
- # SELECT * FROM users
- # WHERE name = "david" AND age > 29
- # ORDER BY name
- # LIMIT 20
- users.order(:name).each { |user| puts user.name }
2. 为Action控制器添加了新的路由进程
示例代码:
- resources :people do
- resource :avatar
- collection do
- get :winners, :losers
- end
- end
- # /sd34fgh/rooms
- scope ':token', :token => /\w{5,5}/ do
- resources :rooms
- end
- # /descriptions
- # /pl/descriptions
- # /en/descriptions
- scope '(:locale)', :locale => /en|pl/ do
- resources :descriptions
- root :to => 'projects#index'
- end
3.全新Action Mailer组件
示例代码:
- class Notifier < ActionMailer::Base
- default :from =>
- "Highrise <system@#{APPLICATION_DOMAIN}>"
- def new_project(digest, project, person)
- @digest, @project, @person = digest, project, person
- attachments['digest.pdf'] = digest.to_pdf
- attachments['logo.jpg'] = File.read(project.logo_path)
- mail(
- :subject => "Your digest for #{project.name}",
- :to => person.email_address_with_name
- ) do |format|
- format.text { render :text => "Something texty" }
- format.html { render :text => "Something <i>texty</i>" }
- end
- end
- end
4. 默认启用跨站点工具 XSS 保护
5. 告别字符编码问题困扰
6. 内部重构
7. 文档完善
8.支持MySQL2 gem
9.修正了自动加载的问题