Perhaps I’m not understanding this very well. I want to set a layout
based on a domain name.
The following works in ApplicationController.rb:
before_filter :set_host
case @host
when ‘site1.com’
layout ‘site1’
when ‘site2.com’
layout ‘site2’
else
layout ‘default’
end
def set_host @host = request.host
end
This returns an error for an undefined “request” method:
case request.host
when ‘site1.com’
layout ‘site1’
when ‘site2.com’
layout ‘site2’
else
layout ‘default’
end
Because the actual controller doesn’t know about the request object
until
you call a method inside of it, like you’re doing with set_host.
Put your case statement inside a method in any controller and it will
work
with request.host.
Because the actual controller doesn’t know about the request object
until
you call a method inside of it, like you’re doing with set_host.
Put your case statement inside a method in any controller and it will
work
with request.host.
Thanks. I understand what you’ve said but why is controller only aware
of the request object inside a method?
before_filter :determine_layout
def determine_layout
case request.host
when ‘site1.com’
layout ‘site1’
when ‘site2.com’
layout ‘site2’
else
layout ‘application’
end
end
It reports there is an undefined method ‘layout’. Why does the layout
method disappear in the method?
It turns out none of this is working. Anyone know why the request
object is not available in ApplicationController in Rails 2.01? Now,
off to check 2.02…
before_filter :determine_layout
def determine_layout
case request.host
when ‘site1.com’
layout ‘site1’
when ‘site2.com’
layout ‘site2’
else
layout ‘application’
end
end
It reports there is an undefined method ‘layout’. Why does the layout
method disappear in the method?