Reputation: 2107
I have a before_filter
which wants to default the response type depending on various aspects of the request and parameters. E.g.,
request.format = ( params.format ||= 'html' ) if ... # an HTML-only request/client
request.format = ( params.format ||= 'json' ) if request.xhr?
the idea being that the respond_to do |format|; format.html { ... }; format.json { ... }
would then render appropriately according to the client conditions. Some of the clients are coming in as type */*
(presumably this is request.content_type
?) and I want to force these to be HTML responses. Doesn't seem to be working however. What is a clean way to do this, and without setting a default type for each route ? I.e. I just want to poke the response type into the request so that respond_to
will switch on it accordingly.
Upvotes: 1
Views: 2640
Reputation: 1448
request.format=
should be an object of type MIME::Type
.
So you'd have to do something like request.format = MIME::Types.type_for('html').first
Upvotes: 1