class RegistrationsController < Devise::RegistrationsController
def create
super
if resource.save
if request.fullpath == '/techie/signup'
resource.role = :techie
resource.save
end
end
end
end
I have this overriding the devise controller and I have a separate sign up view with a path of '/techie/signup/' and I want to add a role to the user based on the page they signed up on. I do not want to put the role in a hidden field as that stuff can be exploited.
Thanks
Try this one.
def create
super do |res|
if request.path_info == '/techie/signup'
res.role = :techie
res.save!
end
end
end
Instead of using request.full_path or request.path_info, using
URI(request.referer).path
solved it.
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.