request.subdomain Returns blank array

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

Hi I am a new Rails Developer

Welcome :slight_smile:

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

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.

https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/url.rb

and the tests:

https://github.com/rails/rails/blob/master/actionpack/test/dispatch/request_test.rb#L154

HTH,

Peter