But why?

Needing to access an item from the params object implies that the value is important for the correct functioning of your action.

If you attempt to access a value using the #[] method and the relevant key is missing, Ruby will return nil. This might lead to confusing NilClass errors if you try and use the result later on.

Using #fetch means the hash will not return nil in the case of a missing key. Instead it’ll raise a KeyError. You want the code to raise an exception at the point where the data is found to be missing, not when that value is used.

Why not?

You might take a view that you simply like the look of the regular #[] hash syntax. After all, it is shorter. But you must be willing to deal with the errors.

If you’re using a parameter in this way you might also consider changing the route to include it. You could make your search route /search/term rather than /search?q=term.

Note that you can use #fetch to provide a default value:

params.fetch(:important){'default'}

This would also help avoid lots of checking for nil in the code where you use the value.