質問について、答えは使用することですinput_html: { value: @user_password }
このような:
<%= f.input :password, :required => true, input_html: { value: @user_password } %>
<%= f.input :password_confirmation, :required => true, input_html: { value: @user_password } %>
パスワード値の復元に関する 2 番目のトピックについては、調査の結果、実際にはセキュリティ バンプのようなものであることがわかりました。本当のセキュリティは、HTTPS を使用するか、クライアント側で javascript を使用してパスワード ハッシュを実行し、サーバーがパスワードを認識しないようにすることによって行われます。
たとえば、https://github.com/joinのような大きな Web サイトでさえ、私のやり方と同じように動作しているようです (パスワードを入力しますが、無効な電子メールを入力すると、パスワードがプレーンな HTMLvalue
要素として入力されます)。
対応するルートとコントローラーは次のようになります。
routes.rb :
devise_for :users, :controllers => {registrations: 'users/registrations' }
registrations_controller.rb :
class Users::RegistrationsController < Devise::RegistrationsController
# build_resource is called inside the new and create methods
def build_resource(*args)
if params[:user]
# So that the password isn't blanked out when the other validations fail. User shouldn't have to retype the password.
@user_password = params[:user][:password]
end
super
end
end