After adding a portfolio_url field to a Rails job-application form, the value never saves and nothing errors; how do you diagnose it and stop it recurring?
answer
- unlisted keys are dropped, not rejected
- Unpermitted parameter log, debug level
- :log in local environments, false elsewhere
- params.expect never logs or raises
- permit! is not the fix
basics
~20 sportfolio_url is missing from the allow-list, so strong parameters drop it silently. permit can log or raise unpermitted keys via action_on_unpermitted_parameters, but params.expect never reports them, so add the key and guard with request tests.
solid answer
~40 sStrong parameters treat unlisted keys as noise: the permitted copy just lacks `portfolio_url`, the model saves without it, and the flash says the application was received. To diagnose, compare the `Parameters:` line in the request log with the keys in `job_application_params`. With `permit`, `config.action_controller.action_on_unpermitted_parameters` defaults to `:log` in development and test and `false` elsewhere, producing a debug line `Unpermitted parameter: :portfolio_url`; setting it to `:raise` makes `permit` raise `ActionController::UnpermittedParameters`. But **`params.expect` never logs or raises for unlisted keys**, so a Rails 8 scaffolded controller stays silent. The durable guard is a request test that posts every form field and asserts the saved record. Never reach for `permit!`: it marks the whole tree permitted and lets `status` and `reviewer_id` back in.
code
ruby · 9 lines# config/environments/development.rb and test.rb
config.action_controller.action_on_unpermitted_parameters = :raise
# Affects permit only:
params.require(:job_application).permit(:full_name)
# => ActionController::UnpermittedParameters: found unpermitted parameter: :portfolio_url
# expect stays silent whatever the setting:
params.expect(job_application: [ :full_name ]) # portfolio_url dropped quietlygo deeper
When a field does not save, compare the Parameters line in the log with the private *_params method before suspecting the model.
Explain action_on_unpermitted_parameters, its :log default in development and test, the UnpermittedParameters error under :raise, and why expect bypasses all of it.
Replace log-based detection with request tests per form, set :raise where permit remains, keep permit! and to_unsafe_h out of review, and treat a form field as a two-file change.
Choose the team's guard for allow-list drift — tests, review checklists or form objects — accepting that production must stay silent about extra client fields.
## Why the value disappears Strong parameters are a **filter**. `permit` and `expect` build a new permitted object from the keys you listed and ignore everything else. When a developer adds `portfolio_url` to the form but not to `job_application_params`, the browser sends it, Rails parses it, and the allow-list leaves it out. The record saves, validations pass, and the flash says "Application received." Nothing failed, so nothing is reported. ## Diagnosing it 1. Read the request log. The `Parameters:` line shows `"job_application" => {..., "portfolio_url" => "https://…"}`, proving the browser sent it under the expected name. 2. Read `job_application_params`. If the key is absent, or declared in the wrong shape — a scalar declared where a hash arrives, or the reverse — that is the cause. 3. Check the model side only after the allow-list is confirmed: a missing column, an `attr_readonly` attribute, or a callback overwriting the value are the next suspects. ## What Rails reports, and when The reporting switch is **`config.action_controller.action_on_unpermitted_parameters`**. When it is not set, Rails uses `:log` in development and test and `false` in every other environment. | Call | `:log` | `:raise` | `false` | |---|---|---|---| | `permit(...)` | debug log line and an `unpermitted_parameters.action_controller` event | raises `ActionController::UnpermittedParameters` | nothing | | `expect(...)` / `expect!(...)` | nothing | nothing | nothing | The `expect` row is the trap. `expect` filters with unpermitted reporting switched off, and Rails' own tests assert that it "never raises on unexpected params" and does not log them. Upgrading a controller from `require(...).permit(...)` to `expect` therefore removes the only warning some teams relied on. Even under `permit`, the log line is written at **debug** level, so it vanishes from logs that run at info. ## Making it loud - **Request tests are the real guard.** Post the full form, including the new field, and assert on the saved record: `assert_equal "https://ada.dev", JobApplication.last.portfolio_url`. This catches the drop whichever API the controller uses. - For controllers still using `permit`, set `:raise` in `config/environments/development.rb` and `test.rb`. When `permit` runs on the root params rather than a nested hash, keys such as `authenticity_token` and `commit` would trip it; `config.action_controller.always_permitted_parameters` (default `%w( controller action )`) lists keys exempt from reporting. - Subscribe to `unpermitted_parameters.action_controller` to count unpermitted keys in environments where `:log` is on. - Treat a new form field as a two-file change: the view and the allow-list, reviewed together. ## A review checklist When a pull request adds or renames a form field, a reviewer can check four things in a minute: 1. The field's name in the view matches a key in the allow-list method, including its nesting. 2. The declared shape matches what is sent: a scalar, a hash, `[]` for scalar arrays or `[[...]]` for lists of hashes. 3. A request test posts the new field and asserts the saved value. 4. No `permit!`, `to_unsafe_h` or `{}` appeared to make the test pass. ## The wrong fixes - **`permit!`** marks the object and every nested `Parameters` inside it as permitted. The field saves — and so does a forged `status` or `reviewer_id`. Mass assignment is open again. - **`to_unsafe_h`** passed to the model does the same thing by another route. - **`config.action_controller.permit_all_parameters = true`** makes every `Parameters` permitted from birth, for the whole app. - **`key: {}`** on the parent hash lets any key through under that parent. Each of these makes the symptom go away by removing the allow-list, which is the mechanism protecting the attributes the form never meant to expose. ## Production judgement Silent drops are a feature in production: a client that sends an extra field should not get errors. The cost is that development needs a deliberate signal. Teams that adopt `expect` everywhere usually pair it with request tests per form, plus a review checklist item that compares form fields with the allow-list. The opposite instinct — turning on `:raise` in production to "never lose data" — trades a silent drop for 500s whenever a browser extension, an old cached form or a third-party client adds a field, and it still would not cover controllers that use `expect`.
- Why might a Rails team see Unpermitted parameter warnings disappear after moving controllers to params.expect?Because `expect` filters with unpermitted reporting turned off. `action_on_unpermitted_parameters` is consulted only by `permit`, so after the switch the debug log line and the `:raise` behaviour stop for those controllers, even though keys are still being dropped. Request tests that assert saved values replace the lost signal.
- What does Rails' always_permitted_parameters setting change?It lists keys that unpermitted-parameter reporting ignores, `controller` and `action` by default. It does not permit them into the result; it only stops `permit` from logging or raising about them, which matters when `permit` is called on the root params where routing keys and form extras such as `commit` live.
- Strong parameters raise an error for every key that is not in the allow-list.
- Setting action_on_unpermitted_parameters to :raise also makes params.expect raise.
- Calling permit! is a safe way to stop fields from being dropped.
- The Unpermitted parameter line appears in production logs by default.
- always_permitted_parameters adds controller and action to the permitted result.