Overriding Devise Registration Create Method

后端 未结 3 1946
情歌与酒
情歌与酒 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:32

    Instead of using super to invoke the Devise::RegistrationsController's create action, replace it with the actual code of Devise::RegistrationsController's create method

    build_resource
    resource.tag_list = params[:tags]   #******** here resource is user 
    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_in(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        expire_session_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      respond_with resource
    end
    

提交回复
热议问题