Rails 4, Empty Hashes, Strong Parameters, exception_notification and filtering out my new ActionController::ParameterMissing errors

I’m finally coming around to the “strong parameters” pattern encouraged (required?) in Rails 4.

One thing that I did notice was that missing the base parameter raised an ActionController::ParameterMissing error. I discovered this via controllers tests generated by rspec-rails when I created a controller scaffold, which generates tests for “Invalid Params”:

In the controller spec:

describe "with invalid params" do
  it "re-renders the 'new' template" do
    # Trigger the behavior that occurs when invalid params are submitted
    User.any_instance.stub(:save).and_return(false)
    post :create, {:user => {  }}, valid_session
    response.should render_template("new")
  end 
end

In the controller:

  def user_params
    params.require(:licensee).permit(:parameter1, :parameter2)
  end

Despite the fact that params[:licensee] exists, the empty hash triggers the ActionController::ParameterMissing error. That’s fine. I can expect { post :create, {:user => { }}, valid_session }.to raise_error(ActionController::ParameterMissing), or eliminate the test altogether.

However, with exception_notifier, I don’t really want to be notified about these errors, so I configured my environment files to filter this exception (and also CanCan::AccessDenied).

  config.middleware.use ExceptionNotification::Rack,
    :ignore_exceptions => %w(CanCan::AccessDenied ActionController::ParameterMissing) + ExceptionNotifier.ignored_exceptions,
    :email => {
      :email_prefix => "[#{Rails.env}] project name exception: ",
      :sender_address => %{"Exception Notifier" <exceptions@example.com>},
      :exception_recipients => [ `git config user.email`.chomp ]
   }