Intern Track Roadmap

Controller params & security

Rails keeps raw request data out of mass assignment through ActionController::Parameters. The lessons show why passing raw params to .new raises ActiveModel::ForbiddenAttributesError and why the permitted? flag starts as false. They cover .permit, which returns an object with only the listed keys. Then comes .require, which steps into the nested key a form submits under. It raises ActionController::ParameterMissing when that key is absent. Real controllers in this project show the pattern, along with params.expect from Rails 8. A sandbox session and the full article_params method close the course.

What you'll learn

  • ✓Why raw params passed to .new raise ActiveModel::ForbiddenAttributesError
  • ✓How the permitted? flag works and why it starts as false
  • ✓Using .permit to keep only the named keys
  • ✓Using .require to enter a nested key and catch a missing one
  • ✓Reading the require and permit pattern in real controllers, plus params.expect
  • ✓Checking params behavior safely in bin/rails console --sandbox
Free preview · Lesson 1 1 min read

Why raw params can't reach .new

ActiveRecord: creating records and ActionController: actions both named article_params as the safe stand-in for raw params without building it. Here's what happens without it:

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...