2

How can I combine Rails' params.require with apiepie's param_group to avoid duplication?

quantumpotato
  • 9,637
  • 14
  • 70
  • 146

1 Answers1

0

I know that it's a little bit late to reply, but here's how to do it:

  1. Create a controller that extends ApiPie:
class ApiController < ActionController::Base extend Apipie::DSL::Concern
  1. Define param_groups in that controller:
def_param_group :param_errors do
    error code: 200, desc: "Success"
    error code: 400, desc: "Error"
    error code: 401, desc: "Unauthorized"
    error code: 404, desc: "Not Found"
end
  1. Extend this controller from your second controller:
class MyCustomController < ApiController
  1. Call the param_group before your function using:
param_group :param_errors, ApiController
def my_method
    # ...
end
zhirzh
  • 3,273
  • 3
  • 25
  • 30
Roc Khalil
  • 1,365
  • 6
  • 22