How to combine two same blocks into one?

advertisements

How can I use a single block in this:

devise_parameter_sanitizer.for(:sign_up) do |u|
  u.permit(:full_name, :email, :password, :password_confirmation)
end
devise_parameter_sanitizer.for(:account_update) do |u|
  u.permit(:full_name, :email, :password, :password_confirmation)
end


Looking at the definition of for, you can see that the kind argument is being used as the key to the @blocks hash. Maybe that is a sign that you shouldn't try to "combine" those two statements.

If you purely want to re-use the codes in the block, just use Proc. So something like:

block = Proc.new do |u|
  u.permit(:full_name, :email, :password, :password_confirmation)
end

devise_parameter_sanitizer.for(:sign_up, block)
devise_parameter_sanitizer.for(:account_update, block)