class <%= controller_class_name %>Controller < ApiController before_action :rewrite_payload, only: :create load_and_authorize_resource def index render json: @<%= controller_class_name.underscore %>.collect(&:list_item_as_json) end def show render json: @<%= controller_class_name.singularize.underscore %>.display_as_json end def create if @<%= controller_class_name.singularize.underscore %>.save render json: { binary_urls: binary_urls(@<%= controller_class_name.singularize.underscore %>), response: @<%= controller_class_name.singularize.underscore %> }, status: :created else head :unprocessable_entity end end private def rewrite_payload Rails.logger.debug "Pre-rewrite params: #{params}" # Use this method to make any changes to parameters # Example to get properties from question # params[:payload][:name] = params.dig(:payload, :name, :answer) # Example to get properties from previous list # passport_id = params.dig(:payload, :choose_passport, :selected, :id) end def <%= controller_class_name.singularize.underscore %>_params # Permit any fields you want to save params.require(:payload).permit(:name) end end