Solved: ActionController::ParameterMissing (param is missing or the value is empty)

Solved: ActionController::ParameterMissing (param is missing or the value is empty)

In Ruby on Rails, strong_params are a necessity to work with ActionController parameters, but sometimes an exception of ActionController::ParameterMissing is thrown… Why?

The Code

params.require(:message).permit(:text, :author_id)

The Exception

ActionController::ParameterMissing (param is missing or the value is empty: message)

The Fix

The error is occurring because our params hash does not include the root key :message. We can diagnose this issue by utilizing params.inspect in either an interactive console or printing the output of certain commands.

The command I tend to use most to identify mishaps is params.inspect.

For example, the output of this command might be:

<ActionController::Parameters {"messages"=>{"text"=>"My Message", "author_id"=>1337}} permitted: false>

In this case, it appears as though there is a typo in our view! The key was typed as messages rather than message. The fix is easy, change the view to submit message instead.


Related Articles