`

Whats New in Edge Rails: Mime::Type Convenience Methods

阅读更多
在需要知道request的mine类型的时候,可以使用一些新加入的方法方便的来做:
ruby 代码
  1.  class MyController < ApplicationController   
  2.   
  3.   # Toggle authentication method based on request type   
  4.   before_filter do |c|   
  5.     c.use_session_auth if c.request.format.html?   
  6.     c.use_token_auth if c.request.format.xml?   
  7.   end  
  8.   
  9. end    
  10.   
  11. class MyController < ApplicationController   
  12.   
  13.   # Turn off sessions for all non-html requests   
  14.   sessions :off:if => Proc.new { |requestnot request.format.html? }   
  15.   
  16. end    
  17.   
  18.   
  19.  # Because I think we all agree I deserve my own mime-type   
  20. Mime::Type.register "text/ryan":ryan  
  21.   
  22. class MyController < ApplicationController   
  23.   
  24.   # Turn off sessions for all ryan requests   
  25.   sessions :off:if => Proc.new { |request| request.format.ryan? }   
  26.   
  27. end    
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics