sent1nel
sent1nel

Reputation: 1780

respond_to works only for the first MIME type in Rails 6

Straight-forward enough problem: everything renders just fine if I remove either geojson or csv, but when both are in the block, the first one is rendered no matter what Content-Type header I send along (text/csv or vnd.geo+json). I do have custom MIME types and renderers, but these don't seem to be the problem since when I use one or the other, everything works as expected, but it is only when I try to reference multiple formats does only the first format end up being used, regardless of header.

      def all
        resource = Thing.where.not(thing_type: BaseThing::ONE_OF_THE_THINGS).order(:unique_id)
        respond_to do |format|
          format.geojson do
            render geojson: Things::GeoSerializer.to_geojson(resource)
          end
          format.csv do
            render csv: Things::CsvSerializer.to_csv(resource), filename: 'things'
          end
        end
      end

Upvotes: 1

Views: 304

Answers (1)

sent1nel
sent1nel

Reputation: 1780

ah; Rails expects the header to be Accept, not Content-Type.

Upvotes: 1

Related Questions