문제

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
도움이 되었습니까?

해결책

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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top