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
精彩评论