I’d like to respond to requests for all kinds of image MIME types from a
single respond_to. In particular, I don’t want to register MIME types
for each image format, I’d rather define only one with a wildcard, like
this
Mime::Type.register ‘image/*’, :image
Then, in the controller handle it like this
def show
respond_to do |format|
format.image do
# check if concrete MIME type can be provided
…
send_file @image.filename, :disposition => ‘inline’
end
format.html do
# send HTML page embedding the image
end
end
end
As it happens, this doesn’t work. Registered MIME types are matched
literally, the ‘*’ is not interpreted as a wildcard.
The best I’ve come up with is this
Mime::Type.register ‘image/png’, :png
Mime::Type.register ‘image/jpeg’, :jpg, [‘image/jpg’], [:jpeg]
and then
format.any(:png, :jpg) do
send_file @image.filename, :disposition => 'inline'
end
Is there a another way?
Michael
–
Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/