I have an app that needs to respond to different url’s. I am using Nginx and want to set the environment variable for host, but I don’t know how to set it or get that env variable back out in the controller. For example, I want something like this…
http://sillyname.com/page_name/home
nginx sets the ENV[‘HOST’] = $host
and rails routes to page controller action => show, params page_name => home. Then in the controllers show action
def show
@website = Website.find_by_host_name(ENV['HOST'])
@page = @website.page.where("title",params[:page_name])
...
end
My specific questions are:
-
what directive do I use in nginx do I use to set this variable, or is it already accessible in a rails 3 app?
-
how do I access the ENV variable in the app to correctly query the db?
You should be able to get the information out of the
requestobject in your controller. Please check specifically:or investigate into