Can't convert nil into String error

Hello,

Why is this code causing the following error:

can’t convert nil into String

class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection
for details

def current_site
return @site if defined?(@site)
@site = Site.find_by_domain(request.domain)
end
end

if I remove this line:

@site = Site.find_by_domain(request.domain)

The error will dissapear.

Any idea what am I doing wrong?

Many thanks for help!

Al F. wrote:

@site = Site.find_by_domain(request.domain)

My guess is that request.domain is somehow return nil. Have you checked
for that?

Robert W. wrote:

Al F. wrote:

@site = Site.find_by_domain(request.domain)

My guess is that request.domain is somehow return nil. Have you checked
for that?

Hi Al F,

First check the parameter ‘request’ by

puts request.inspect

It returns the domain name ‘nil’, if you are working in your local
system and it returns domain name, if you check it in any server.

thanks,
vaddi