Rails2的部分新特性

1.Action Pack: Resources

map.namespace(:admin) do |admin|  

  admin.resources :products,  

    :collection => { :inventory => :get },  

    :member     => { :duplicate => :post },  

    :has_many   => [ :tags, :images, :variants ]  

end 

image image

2. Action Pack: HTTP Loving

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 

3. Action Pack: Exception handling

大多数常见的异常都可以统一处理,而不是每个需要单独的处理。通常情况下,你只需要覆盖rescue_action_in_public方法,来进行统一的异常处理即可。但是你也有可能需要使用自己的case语句来处理特定场合的异常。因此我们现在提供了一个类级别的宏叫做rescue_from,你可以使用它来声明针对某个特定的Action来捕获异常

class PostsController < ApplicationController  

  rescue_from User::NotAuthorized, :with => :deny_access 

  protected  

    def deny_access  

      ...  

    end 

end 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值