ruby on rails - How to redirect based on the type of model in devise? -
ruby on rails - How to redirect based on the type of model in devise? -
i working on new rails 3 application. in application have 2 different types of resources(admin , garage) both different views , 2 different login screens using devise. admin can create garage , can generate password garage using garage manager can login application. till able implement this.
one problem facing in above implementation garage manager, 1 time logged in, able view admin section changing url in browser , can create changes admin user.
now trying implement have single log in/sign in form both models , when logs in, depending on model type should redirected respective views. also, restrict users admin using admin section.
what should approach implement this. using devise authentication.
resource
instance of 1 of models here:
def after_sign_in_path_for(resource) homecoming admin_route_path if resource.is_a?(admin) homecoming garage_route_path if resource.is_a?(garage) end
resource
symbol of model name here:
def after_sign_out_path_for(resource) homecoming "/admin" if resource == :admin homecoming "/" if resource == :garage end
normally goes in application_controller.rb
one problem facing in above implementation garage manager, 1 time logged in, able view admin section changing url in browser , can create changes admin user.
as this, it's authorization problem , not authentication problem. though can simple stuff within devise manage this, admin flag or of nature can differentiate two. redirecting won't solve issue entirely.
take @ cancan, declarative authorization , i'm sure there many others.
ruby-on-rails devise ruby-on-rails-3.2
Comments
Post a Comment