Added ability to use Ahoy-Visit header
Andrew Kane
committed Apr 20, 2014
commit 62dfad63db28102205be1fd33ae586fdc2111521
Showing 3
changed files with
7 additions
and 5 deletions
app/controllers/ahoy/visits_controller.rb
+1
-1
| @@ | @@ -15,7 +15,7 @@ module Ahoy |
| end | |
| visit.save! | |
| - | render json: {id: visit.id} |
| + | render json: {visit_token: visit.visit_token} |
| end | |
| protected | |
ahoy/controller.rb b/lib/ahoy/controller.rb
+3
-2
| @@ | @@ -11,8 +11,9 @@ module Ahoy |
| protected | |
| def current_visit | |
| - | if cookies[:ahoy_visit] |
| - | @current_visit ||= Ahoy.visit_model.where(visit_token: cookies[:ahoy_visit]).first |
| + | visit_token = cookies[:ahoy_visit] || request.headers["Ahoy-Visit"] |
| + | if visit_token |
| + | @current_visit ||= Ahoy.visit_model.where(visit_token: visit_token).first |
| end | |
| end | |
ahoy_matey.rb b/lib/ahoy_matey.rb
+3
-2
| @@ | @@ -32,8 +32,9 @@ ActiveRecord::Base.send(:extend, Ahoy::Model) if defined?(ActiveRecord) |
| if defined?(Warden) | |
| Warden::Manager.after_set_user except: :fetch do |user, auth, opts| | |
| request = Rack::Request.new(auth.env) | |
| - | if request.cookies["ahoy_visit"] |
| - | visit = Ahoy.visit_model.where(visit_token: request.cookies["ahoy_visit"]).first |
| + | visit_token = request.cookies["ahoy_visit"] || request.headers["Ahoy-Visit"] |
| + | if visit_token |
| + | visit = Ahoy.visit_model.where(visit_token: visit_token).first |
| if visit | |
| visit.user = user | |
| visit.save! | |