0
我試圖生成一個隨機字符串並將其保存到名爲railsid的用戶字段中。我已經覆蓋了設計用戶的registrations_controller.rb。我希望在創建對象時將隨機生成的字符串保存到用戶對象中。當我進入rails控制檯查看用戶是否保存了railsid時,它返回nil。保存用戶之前Rails 4更新設計註冊控制器中的字段
registrations_controller.rb
class Lenders::RegistrationsController < Devise::RegistrationsController
before_filter :update_sanitized_params
def new
super
end
def create
@user = User.new(params[:user])
@user.railsid = '%010d' % rand(10 ** 10)
super
end
def edit
super
end
def update
super
end
def authenticate_scope!
send(:"authenticate_user!", :force => true)
self.resource = send(:"current_user")
end
private
def update_sanitized_params
devise_parameter_sanitizer.for(:sign_up) {|u| u.permit(:email, :password, :password_confirmation, :type, :confirmed_at, :first_name, :last_name, :railsid)}
end
def after_sign_up_path_for(resource)
root_path
end
end