require

require(key)
Instance Public methods

Ensures that a parameter is present. If it's present, returns the parameter at the given key, otherwise raises an ActionController::ParameterMissing error.

1
2
3
4
5
6
7
8
ActionController::Parameters.new(person: { name: 'Francesco' }).require(:person)
# => {"name"=>"Francesco"}
 
ActionController::Parameters.new(person: nil).require(:person)
# => ActionController::ParameterMissing: param not found: person
 
ActionController::Parameters.new(person: {}).require(:person)
# => ActionController::ParameterMissing: param not found: person

required

doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.