Question

basically i have Admin and User in my app. Here after signing by user it is also routing user_dashboard but if i make change in url as admin_dashboard it is getting routed for that also. How can i stop that

similarly if Admin get sign in it is also routing to Admin_dashboard but if i make change in url as user_dashboard it get routed. How can i restrict that

class ApplicationController < ActionController::Base

  protect_from_forgery

  skip_before_filter :authenticate_user! , :only => ["welcome#index"]

  def after_sign_in_path_for(user)  
     user_dashboard_index_path
   end

   def after_sign_out_path_for(user)
    welcome_index_path
  end
end
Was it helpful?

Solution

I believe the way to do this is to override the devise before and after_sign_in_path_for helpers

I think (from what I've read), you can use logic to determine the best way to handle this:

def after_sign_in_path_for(resource)
  stored_location_for(resource) ||
    if resource.is_a?(Admin)
      admin_dashboard_path
    else
      user_path(resource)
    end
end

OTHER TIPS

If you have any field like "is_admin" in user model then you need to just check whether logged in user is admin or not.

like

def after_sign_in_path_for(user)
  if user.is_admin?
    admin_dashboard_index_path
  else
    user_dashboard_index_path
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top