Back to Course

Practice · Reading the Source · Card 3

require vs []: what's the failure mode?

Two ways to reach into params for the same data. When the form submits without the expected key, they fail differently. The difference matters.

The code

A POST comes in with no post key in the body.

# Version 1:
params.require(:post).permit(:title, :body)

# Version 2:
params[:post].permit(:title, :body)

The question

Both versions fail when the post key is missing. Which pair of errors do they raise?

Take a moment. Pick the best answer. Wrong picks reveal why they're wrong, which is half the point.