簡體   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

我具有覆蓋設計控制器的權限,並且具有一個單獨的注冊視圖,其路徑為“ / techie / signup /”,我想根據用戶注冊的頁面向用戶添加角色。 我不想將角色放在隱藏的字段中,因為可以利用這些東西。

謝謝

試試這個。

  def create
    super do |res|
      if request.path_info == '/techie/signup'
         res.role = :techie
         res.save!
      end  
    end  
  end

代替使用request.full_path或request.path_info,使用

URI(request.referer).path 

解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM