ActionController::Renderers.add :csv do |resource, options, *rest| builder_class = options[:builder] || CsvBuilder.find_for_route("#{controller_path}##{action_name}") raise "Cannot find the Csv builder for: #{controller_path}##{action_name}" unless builder_class.present? builder = builder_class.new(resource, options.merge(action_name: action_name, controller_path: controller_path, controller: self)) send_data builder.data, type: Mime::CSV, disposition: "attachment; filename=#{builder.file_name}" end