Skip to content

Stop submitting registration_form_id as an unpermitted event param#1542

Open
maebeale wants to merge 1 commit into
mainfrom
maebeale/fix-event-registration-form-param
Open

Stop submitting registration_form_id as an unpermitted event param#1542
maebeale wants to merge 1 commit into
mainfrom
maebeale/fix-event-registration-form-param

Conversation

@maebeale
Copy link
Copy Markdown
Collaborator

@maebeale maebeale commented Jun 5, 2026

Closes #1536

What is the goal of this PR and why is this important?

  • The event form posted the registration-form selector as event[registration_form_id], but registration_form_id is not an Event attribute.
  • The registration form is persisted through the event_forms join (see EventsController#assign_event_forms), not via mass assignment.
  • Because the field was nested under event[...], strong params rejected it as an unpermitted parameter and logged a warning on every event create/update — which is exactly what the issue flagged ("Why is this submitted and do we need it?").

We do need the value (it drives which registration form gets linked) — it just shouldn't live inside the event[...] namespace.

How did you approach the change?

  • Renamed the select from event[registration_form_id] to a top-level registration_form_id in app/views/events/_form.html.erb.
  • Updated assign_event_forms to read params[:registration_form_id] instead of params.dig(:event, :registration_form_id).
  • No behavior change for users: selecting a form still links it, and selecting "No registration form" still removes it.

Anything else to add?

  • Added request specs covering create/update/blank that assert the form is linked and that registration_form_id is no longer reported via the unpermitted_parameters.action_controller notification.
  • Note: a few unrelated event view-rendering specs (GET /index, /new, /show) currently return 500 in this local environment even on a clean main checkout (asset/CSP rendering), so they are not affected by this change.

🤖 Generated with Claude Code

The registration form selector is not an Event attribute — it is
persisted through the event_forms join in assign_event_forms. Nesting
the field under event[registration_form_id] meant strong params rejected
it as unpermitted and logged a warning on every event create/update.

Move the field out of the event[...] namespace to a top-level
registration_form_id param so the value reaches assign_event_forms
without tripping the unpermitted-parameter filter.

Closes #1536

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 5, 2026 00:32

def assign_event_forms(event)
form_id = params.dig(:event, :registration_form_id)
form_id = params[:registration_form_id]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the top-level params[:registration_form_id] instead of params.dig(:event, :registration_form_id). This value isn't an Event column — it's resolved into the event_forms join below — so keeping it out of the event[...] namespace is what stops strong params from logging it as unpermitted.

@registration_forms.find { |rf| rf.name == ShortEventRegistrationFormBuilder::FORM_NAME }&.id
end %>
<select name="event[registration_form_id]" class="w-full rounded border-gray-300 shadow-sm px-3 py-2 text-sm">
<select name="registration_form_id" class="w-full rounded border-gray-300 shadow-sm px-3 py-2 text-sm">
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field renamed from event[registration_form_id] to registration_form_id. The selector drives assign_event_forms, not mass assignment, so it belongs at the top level of the params rather than nested under the event resource.

@maebeale maebeale marked this pull request as ready for review June 5, 2026 00:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes registration_form_id from the nested event[...] params namespace (where it is not a real Event attribute) and instead submits it as a top-level parameter, matching how registration forms are actually persisted via the event_forms join.

Changes:

  • Update the event form to submit registration_form_id as a top-level param (not event[registration_form_id]).
  • Update EventsController#assign_event_forms to read params[:registration_form_id].
  • Add request specs covering create/update/blank submission, including an assertion that the param is not reported as unpermitted.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
app/views/events/_form.html.erb Moves the registration form selector out of event[...] to avoid strong-params “unpermitted” noise.
app/controllers/events_controller.rb Reads registration_form_id from the top-level params in assign_event_forms.
spec/requests/events_spec.rb Adds request coverage for linking/unlinking the registration form and checking for unpermitted-param notifications.

Comment on lines +388 to +390
subscriber = ActiveSupport::Notifications.subscribe("unpermitted_parameters.action_controller") do |*args|
captured.concat(args.last[:keys])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event edit form submits registration_form_id as an unpermitted param

2 participants