Rails Request Environment Variables

Handwritten by TVD

You are an internet savvy Starter. So, I hope you’re paying attention to your users somehow! Well, there’s gonna come a time when you’ll need to do some analytic gathering yourself. Rails environment variables can come in handy then.

I’ve written quite a few Ruby on Rails tutorials so far. I hope this Rails tutorial also helps you reach your destination.

Using Rails Request.env

Here’s an example of using the Rails request.env object:

@contact = Contact.new
@contact.referrer = request.env["HTTP_REFERER"]
@contact.user_agent = request.env["HTTP_USER_AGENT"]

Rails Request.env List

Request.env is a Rails object that contains information on your visitor’s environment (e.g. browser, referrer) and information on your server’s environment. The request.env object is a key/value pair Ruby array. Here is the list of the environment variables you have access to:

# Rails Request.env Variables
SERVER_NAME
PATH_INFO
REMOTE_HOST
HTTP_ACCEPT_ENCODING
HTTP_USER_AGENT
SERVER_PROTOCOL
HTTP_CACHE_CONTROL
HTTP_ACCEPT_LANGUAGE
HTTP_HOST
REMOTE_ADDR
SERVER_SOFTWARE
HTTP_KEEP_ALIVE
HTTP_REFERER
HTTP_COOKIE
HTTP_ACCEPT_CHARSET
REQUEST_URI
SERVER_PORT
GATEWAY_INTERFACE
QUERY_STRING
REMOTE_USER
HTTP_ACCEPT
REQUEST_METHOD
HTTP_CONNECTION

Good Luck Beloved! Have Fun!

discuss on twitter


every day thousands of developers use our charts & gauges to get the job done right

JavaScript Charts JavaScript Gauges JavaScript Flight Gauges


← return to all articles