Skip to content

Instantly share code, notes, and snippets.

@richmolj
Created May 3, 2018 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richmolj/0311f07c3ff135a8da1fdbb681a431f0 to your computer and use it in GitHub Desktop.
Save richmolj/0311f07c3ff135a8da1fdbb681a431f0 to your computer and use it in GitHub Desktop.
# config/initializers/strong_resources.rb
Parameters = ActionController::Parameters
# first, define our custom type according to the stronger_parameters documentation
custom_type = Parameters.array(Parameters.id)
# then, register this custom type with strong resources. we need:
# * a name for the type (:array_of_integers)
# * since swagger only allows certain types, how should swagger handle this type?
# * the type defined above
strong_param :array_of_integers, swagger: :array, type: custom_type
strong_resource :thing do
# And now use it just like you would :string, :integer, etc
attribute :foo, :array_of_integers
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment