Trying to make a mobile version of the site with the subdomain "m".
ApplicationController:
class ApplicationController < ActionController::Base before_filter :redirect_to_mobile def redirect_to_mobile if mobile_browser? && !mobile_request? redirect_to "m." + request.host_with_port.gsub(/^www\./, '') and return end end def mobile_browser? request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad|Android)/] end helper_method :mobile_browser? def mobile_request? request.subdomain.split('.')[0] == 'm' end helper_method :mobile_request? end Redirect goes to the right address, but the page does not load. I use the android emulator from sdk, I get "This site can`t be reached".
Started GET "/" for 192.168.1.47 at 2017-01-24 20:24:47 +0300 Cannot render console from 192.168.1.47! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by WelcomeController#index as HTML Parameters: {"subdomain"=>""} request.url: http://test.ru:3000/ ITS Mozilla/5.0 (Linux; Android 7.1; Android SDK built for x86_64 Build/NPF26K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.135 Mobile Safari/537.36 Redirected to m.test.ru:3000 Filter chain halted as :redirect_to_mobile rendered or redirected Completed 302 Found in 1ms (ActiveRecord: 0.0ms) If the same address is opened manually, everything is loaded correctly.