Overriding Devise Registration Create Method

后端 未结 3 1944
情歌与酒
情歌与酒 2020-12-31 04:47

I want to specifically set a field when a user is created. I have

class RegistrationsController < Devise::RegistrationsController
  def create
    super
          


        
3条回答
  •  隐瞒了意图╮
    2020-12-31 05:34

    If you don't want to rewrite the entire code of the create method, you can simply set the resource variable inside the protected method :build_resource of Devise::RegistrationsController, which is called before the resource is saved.

    protected 
    
    # Called before resource.save
    def build_resource(hash=nil)
      super(hash)
      resource.tag_list = params[:tags]
    end
    

提交回复
热议问题