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

On Thu, Feb 9, 2012 at 4:58 PM, Kausik B. [email protected]
wrote:

Hi I am a new Rails Developer

Welcome :slight_smile:

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


*** Available for a new project ***

Peter V.
http://twitter.com/peter_v
http://rails.vandenabeele.com
http://coderwall.com/peter_v

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs