Rails Request Environment Variables

Rails Request Environment Variables

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!

Credits to: TVD

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.

This site uses Akismet to reduce spam. Learn how your comment data is processed.