Why does double splat only work with symbol keys?

I ran into something like this recently.

If you’re in Rails and you have a method that takes keyword arguments and you have a strong params hash that you want to send to it, you can use symbolize_keys on the params hash and it will properly separate out the arguments, no double splat needed.

Model

class ContactForm
  def initialize(name:, email:)
    @name = name
    @email = email
  end
  # Other stuff
end

Controller

class ContactController < ApplicationController
  def send_mail
    @contact_form = ContactForm.new(contact_params)
    if @contact_form.submit
      # Do stuff
    end
  end

  def contact_params
    params.require(:contact_form).permit(:name, :email).symbolize_keys
  end
end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)