开发者

Change request format based on subdomain in Rails 3

On my Rails 3 site, if a user comes in through a certain subdomain (say, mob.example.com), I want to change the request format of that request to be ":mobile".

What's the most sensible way to do this, 开发者_运维百科and where should I put this code?


I wound up doing this in the way I thought was most reasonable:

module MobilizedController
  extend ActiveSupport::Concern

  included do
    before_filter :set_mobile_request_format, :if => :mobile_subdomain?
  end 

  private

  def set_mobile_request_format
    request.format = :mobile
  end 

  def mobile_subdomain?
    request.subdomains.include? 'm' 
  end 
end

class ApplicationController
  include MobilizedController
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜