设计默认创建动作是什么样的?

时间:2013-08-13 17:23:01

标签: ruby-on-rails

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

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

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

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

1 个答案:

答案 0 :(得分: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