# Respond\_to with MIME type wildcards?

**URL:** <https://www.ruby-forum.com/t/respond-to-with-mime-type-wildcards/120509>\
**Category:** Rails\
**Created:** [November 17, 2007, 6:25pm UTC](https://www.ruby-forum.com/t/respond-to-with-mime-type-wildcards/120509 "2007-11-17T18:25:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [November 17, 2007, 6:25pm UTC](https://www.ruby-forum.com/t/respond-to-with-mime-type-wildcards/120509/1 "2007-11-17T18:25:05Z")

</div>

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:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)
