Hi I am a new Rails Developer
My application_controller is:
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :sshow
def sshow
puts “===========================”
puts YAML::dump(request.subdomains)
end
end
now when I put kausik.localhost:3000 in my browser address bar it
returns blank Array [] instead [‘kausik’] .
Also I rewrite etc/host file for this subdomain.
Please help me
Thanks & regards
Kausik
circar
February 9, 2012, 6:34pm
2
On Thu, Feb 9, 2012 at 4:58 PM, Kausik B. [email protected]
wrote:
Hi I am a new Rails Developer
Welcome
puts YAML::dump(request.subdomains)
end
end
now when I put kausik.localhost:3000 in my browser address bar it
returns blank Array [] instead [‘kausik’] .
Also I rewrite etc/host file for this subdomain.
Please help me
What happens with this domain
sub.kausik.localhost:3000 ?
I think in such a domain structure:
E.D.C.B.A
it only takes domains to the left of ‘B’ (index less than -2)
(counting from right to left). (That is for .com, .be etc.
might be automatically set to 3 for .co.uk ?).
But it can be modelled with tld_length etc.
It seems, you could do
request.subdomains(-1)
and get everything to the left of ‘A’
Check e.g.
# frozen_string_literal: true
require "active_support/core_ext/module/attribute_accessors"
module ActionDispatch
module Http
module URL
IP_HOST_REGEXP = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
HOST_REGEXP = /(^[^:]+:\/\/)?(\[[^\]]+\]|[^:]+)(?::(\d+$))?/
PROTOCOL_REGEXP = /^([^:]+)(:)?(\/\/)?$/
mattr_accessor :secure_protocol, default: false
mattr_accessor :tld_length, default: 1
class << self
# Returns the domain part of a host given the domain level.
#
# # Top-level domain example
# extract_domain('www.example.com', 1) # => "example.com"
# # Second-level domain example
This file has been truncated. show original
and the tests:
test "remote ip v6" do
request = stub_request "REMOTE_ADDR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip
request = stub_request "REMOTE_ADDR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,2001:0db8:85a3:0000:0000:8a2e:0370:7334"
assert_equal "2001:0db8:85a3:0000:0000:8a2e:0370:7334", request.remote_ip
request = stub_request "REMOTE_ADDR" => "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329"
assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip
request = stub_request "REMOTE_ADDR" => "::1",
"HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329"
assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip
request = stub_request "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,unknown"
assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip
request = stub_request "HTTP_X_FORWARDED_FOR" => "fe80:0000:0000:0000:0202:b3ff:fe1e:8329,::1"
assert_equal "fe80:0000:0000:0000:0202:b3ff:fe1e:8329", request.remote_ip
HTH,
Peter
–
*** Available for a new project ***
Peter V.
http://twitter.com/peter_v
http://rails.vandenabeele.com
http://coderwall.com/peter_v