I’m trying to make the user fill out a questionnaire if it is their first time visiting the site.
My controllers are set up like this:
class MainController < BaseController
end
class BaseController < ApplicationController
before_filter :first_time_visiting?
end
class ApplicationController < ActionController::Base
def first_time_visiting?
if session[:first_time].nil?
session[:first_time] = 1
redirect_to questionnaire_path unless current_user
end
end
end
When I close the browser and re-open it though, I always get redirected to the questionnaire.
You have to set a cookie in the browser for that user in order to allow detection at a later time, i.e. after the user closes the browser. Setting and reading cookies in rails is easy. Checkout the documentation for some example usage. http://api.rubyonrails.org/classes/ActionDispatch/Cookies.html