Make sure visit exists first

Andrew Kane committed Mar 02, 2014
commit 2338ae5af870052ab3ea920595f9f853af74dce0
Showing 2 changed files with 5 additions and 6 deletions
README.md +1 -1
@@ @@ -51,7 +51,7 @@ You can store the visit id on any model. For instance, when someone places an or
```ruby
Order.create(
- visit_id: current_visit.id,
+ visit_id: current_visit.try(:id),
# ... other attributes ...
)
```
ahoy_matey.rb b/lib/ahoy_matey.rb +4 -5
@@ @@ -15,14 +15,13 @@ ActionController::Base.send :include, Ahoy::Controller
if defined?(Warden)
Warden::Manager.after_authentication do |user, auth, opts|
- p user
- p auth.env
- p opts
request = Rack::Request.new(auth.env)
if request.cookies["ahoy_visit"]
visit = Ahoy::Visit.where(visit_token: request.cookies["ahoy_visit"]).first
- visit.user = user
- visit.save!
+ if visit
+ visit.user = user
+ visit.save!
+ end
end
end
end