Advertisement
terraplane

Untitled

Jan 11th, 2022
1,560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.71 KB | None | 0 0
  1. class ApplicationForm
  2.   include ::ActiveModel::Model
  3. end
  4.  
  5. class SecurityForm < ApplicationForm
  6.   attr_accessor :current_password, :password, :password_confirmation
  7.  
  8.   validates :current_password, :password, :password_confirmation, presence: true
  9.  
  10.   def update
  11.     return false unless valid?
  12.  
  13.     self
  14.   end
  15. end
  16.  
  17. class SecurityController < AuthController
  18.   def update
  19.     @security_form = SecurityForm.from_params(form_params, record: current_user)
  20.     if @security_form.update
  21.       # redirect_to next step with all params
  22.     else
  23.       # render errors
  24.     end
  25.   end
  26.  
  27.   def form_params
  28.     params.require(:security_form).permit(:current_password, :password, :password_confirmation)
  29.   end
  30. end
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement