I have two devise models namely user
and technician
. I want technicians
to be directed to a particular page when they login so I implemented it according to the devise tutorial and put this in the application controller
def after_sign_in_path_for(resource)
case resource.class
when technician
new_services_path
when user
root_path
end
end
but I get this error. [![enter image description here][1]][1] what am I missing here?
You need to update your switch
. resource.class
will return class of the resource ( User
or Technician
). So, you modify your method as follow:
def after_sign_in_path_for(resource)
case resource.class
when Technician
new_services_path
when User
root_path
end
end
Classes are being written with capital letter: Technician
, User
. The following code should work:
def after_sign_in_path_for(resource)
case resource.class
when Technician
new_services_path
when User
root_path
end
end
You can try this.
def after_sign_in_path_for(resource)
case resource.class.name
when "Technician"
new_services_path
when "User"
root_path
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.