Ruby on Rails 2.0的新特性介绍
http://tech.ddvip.com 2008年01月18日 社区交流
内容摘要:在详细的介绍Rails2.0之前,我要向那些为Rails框架做出过贡献的每一个人致以深深的谢意,不论是像一个家庭那样其乐融融的Rails核心开发团队,还是成千上万的、而且年复一年为Rails提交补丁,积极参与Rails社区人们。Rails2.0也是大规模开源软件开发社区的一个重大胜利,而你完全可以自豪于你在Rails社区当中扮演的角色和做出的贡献。干杯!
# person is a Person object, which by convention will
# be mapped to person_url for lookup
redirect_to(person)
link_to(person.name, person)
form_for(person)
Action Pack: HTTP Loving
如你所期望的那样,Rails2.0的Action Pack更加贴近HTTP,并且充分利用HTTP协议,例如资源、多种视图,还有更多的呢。我们添加了一个模块来处理HTTP的Basic验证,它能够让授权的API轻松跨越SSL协议,而且他是如此的简单易用。下面是一个例子(更多的例子请参考ActionController::HttpAuthentication):
class PostsController < ApplicationController
USER_NAME, PASSWORD = "dhh", "secret"
before_filter :authenticate, :except => [ :index ]
def index
render :text => "Everyone can see me!"
end
def edit
render :text => "I'm only accessible if you know the password"
end
private
def authenticate
authenticate_or_request_with_http_basic do |user_name, password|
user_name == USER_NAME && password == PASSWORD
end
end
end
此外,我们也做了很多工作让你把JavaScript和CSS文件组织到一个逻辑单元里面去,而不需要让浏览器发起多次HTTP请求,分别获取每个JavaScript和CSS文件,以便减少HTTP请求次数。使用javascript_include_tag(:all, :cache => true) 这个helper在生产环境下自动把public/javascripts/目录下面的所有js文件打包到单个public/javascripts/all.js文件里面,但在开发环境下,仍然保持每个文件独立的修改。
来源:javaeye 作者:robbin 责编:豆豆技术应用