0

所以,我想将这段代码添加到设计注册控制器中。

当我打电话时@user.save。就在此之前,我需要打电话,@user.uid = SecureRandom.hex(whatever-value).

但是,我不想更改 create 操作当前的运行方式。我只想添加@user.id = SecureRandom.hex一行。

那么,原始设计如何创建动作呢?

4

1 回答 1

1

https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb

def create
    build_resource(sign_up_params)

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_up(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
  end

更多文档:

https://github.com/plataformatec/devise/wiki

于 2013-08-13T17:34:24.280 回答