Module: RequireParams::ClassMethods

Defined in:
lib/require_params.rb

Instance Method Summary collapse

Instance Method Details

#require_params(required_params, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/require_params.rb', line 5

def require_params(required_params, options = {})
  before_action options do
    missing_params = required_params.reject { |x| params.has_key?(x) }
    if missing_params.any?
      render json: { errors: missing_params.map { |x| {x => ["is missing"]}} }, status: :bad_request
      false
    end
  end
end