Reputation: 5210
I'm using devise as registration engine in my rails 3.1 app. How can i prevent users from accessing some pages when they are logged in? I need to disable devise registration and some custom pages? Is there any way to implement this?
Upvotes: 0
Views: 281
Reputation: 3642
Devise automatically handles redirecting logged in users away from the sign in and sign up actions. If you would like to do this for other pages you would need to use controller before filters or an authorization solution such as CanCan.
You could quickly do a controller filter to redirect logged in users like so in a controller:
def SomeController < ApplicationController
before_filter :redirect_logged_in_user, :only => :action_to_prevent
private
def redirect_logged_in_user
redirect_to your_redirect_path if current_user
end
end
Upvotes: 1
Reputation: 1373
Devise is authentication system. To control users access to some pages you need authorization. For example, https://github.com/ryanb/cancan
Upvotes: 1