Last active
January 1, 2016 21:09
-
-
Save bookis/8202150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#... | |
def current_visitor # This could be any name, `current_visitor` is just descriptive | |
if session[:visitor_id] # checking if the session hash has a key of :visitor_id | |
Visitor.find(session[:visitor_id]) # If there is a visitor id, find the Visitor by what is in the value of session[:visitor_id] | |
else | |
visitor = Visitor.create(ip_address: request.remote_ip) # If no session visitor id, create a new visitor assigning the ip_address | |
session[:visitor_id] = visitor.id # set the session hash visitor_id key to be the id of the record just created | |
visitor # return the visitor object that you just created, otherwiet the line above would be the last thing returned, but we want a Visitor object to be returned | |
end | |
end | |
#... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment