Module: ActionArgs
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rails-action-args/abstract_controller.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#send_action(action) ⇒ Object
Calls an action and maps the params hash to the action parameters.
Instance Method Details
#send_action(action) ⇒ Object
Calls an action and maps the params hash to the action parameters.
Parameters
- action<Symbol>
-
The action to call
Raises
- BadRequest
-
The params hash doesn’t have a required parameter.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rails-action-args/abstract_controller.rb', line 34 def send_action(action) arguments, defaults = self.class.action_arguments(action.to_s) args = arguments.map do |arg, default| p = params.key?(arg.to_sym) unless p || (defaults && defaults.include?(arg)) missing = arguments.reject {|arg| params.key?(arg[0].to_sym || arg[1])} raise AbstractController::BadRequest, "Your parameters (#{params.inspect}) were missing #{missing.join(", ")}" end p ? params[arg.to_sym] : default end super(action, *args) end |