简体   繁体   English

我在这里做错了什么? 通过设计注册并添加角色

[英]what am I doing wrong here? Registration with devise and adding a role

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. 我具有覆盖设计控制器的权限,并且具有一个单独的注册视图,其路径为“ / techie / signup /”,我想根据用户注册的页面向用户添加角色。 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 代替使用request.full_path或request.path_info,使用

URI(request.referer).path 

solved it. 解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM