我有一個名爲password和phone_number的用戶模型。在創建用戶時,我需要電子郵件和密碼,但我需要一個表格另一個頁面添加電話號碼!做一個form_for將數據添加到現有模型(導軌)
我嘗試這樣做:
= form_for @user do |f|
= f.label :phone_number
= f.text_field :phone_number
%p.button
= f.submit
問題的是,它擊中其詢問password_reset用戶更新:
users_controller.rb
def update
if current_user
@user = current_user
else
@user = User.find(params[:id])
end
@user.password_hash = nil
if @user.update_attributes(params[:user])
redirect_to @user, :notice => "Password has been changed!"
else
render "edit"
end
end
我怎麼能修復這個?
我不明白這個問題,是不是正確更新了?什麼是password_reset? – Roy
Roy!怎麼了大聲笑。是的,密碼重置工作正常,但我只是試圖讓它在一個新的形式添加phone_number。當我提交我得到的錯誤'密碼不能爲空' –
我想我正在尋找一種方法,使用戶更新時,還添加phone_number當在該頁 –