Skip to content

Commit 0956ac4

Browse files
committed
Login redirect
1 parent d33cdbd commit 0956ac4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,15 @@ config.sign_out_via = :delete
152152
#### Commit: 'Post controller and forms setup', [a915038](https://github.com/robault/ActsAsTenantExample/commit/a9150389d63cde9a3deae72f3a8148c07009f3e2)
153153

154154
---
155+
156+
At this point I was able to regster two new users ([email protected], [email protected]), login, and create posts which only show up based on the tenant associated with the post. Which, in this case is "User".
157+
158+
This next part wasn't in the video but I added a redirect after login to the posts index page:
159+
160+
```ruby
161+
def after_sign_in_path_for(resource)
162+
stored_location_for(resource) || posts_path
163+
end
164+
```
165+
166+
This takes you right to posts so you can see that they are being filtered.

app/controllers/application_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ class ApplicationController < ActionController::Base
55
def set_tenant
66
set_current_tenant(current_user) # this determines the tenant, for now the lookup is done based on the Devise current_user
77
end
8+
9+
# I'm adding this method to redirect the user to the posts page after login
10+
def after_sign_in_path_for(resource)
11+
stored_location_for(resource) || posts_path
12+
end
813
end

0 commit comments

Comments
 (0)