Empty hash triggers ParameterMissing exception when using #require #65

nullstyle opened this Issue Nov 30, 2012 · 2 comments


None yet

2 participants


The following snippet illustrates this behavior:

params = ActionController::Parameters.new(:user => {})
params.require(:user) # raises exception
# ActionController::ParameterMissing: key not found: user

Granted this is an edge case, but it does make using #require when all parameters underneath :user are optional a bit unwieldy.

Would it be reasonable to turn:

def require(key)
  self[key].presence || raise(ActionController::ParameterMissing.new(key))

into something like:

def require(key)
  found = self[key]      
  raise(ActionController::ParameterMissing.new(key)) unless found.is_a?(Hash)

This was discussed in ec02f78#commitcomment-1800334


IMO, the problem with just using params[:user] instead of params.require(:user) is that it lets through the class of errors as described by DHH in his comment here: #2 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment