# Display SVG challenge

**URL:** <https://www.ruby-forum.com/t/display-svg-challenge/88500>\
**Category:** Rails\
**Created:** [March 12, 2007, 4:49am UTC](https://www.ruby-forum.com/t/display-svg-challenge/88500 "2007-03-12T04:49:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 12, 2007, 4:49am UTC](https://www.ruby-forum.com/t/display-svg-challenge/88500/1 "2007-03-12T04:49:31Z")

</div>

Here’s a challenge to all you good rails programmers: how does one  
display SVG images in Rails ? Now I realize many of you ignore SVG  
since it “isn’t supported everywhere” but that is rapidly changing (it  
is supported in Firefox since 1.5, it’s now in the Safari overnight  
builds, and in IE under the SVG plugin - which is usually shipped but  
not activated with the Adobe plugins.

Since SVG can be displayed in ordinary HTML (using \<embed type=image/  
svg+xml in Firefox), I can only think of 2 reasons that it is not  
recognized under Rails:

1. maybe Webrick or Mongrel doesn’t recognize it ?
2. somewhere Rails doesn’t recognize the mime type - I’ve tried  
changing mime in 2 locations:  
a) in the environment.rb file under myproject/config  
adding Mime::Type.register “image/svg+xml” (also tried “application/  
xhtml+xml”)

b) in httputils.rb under /usr/lib/ruby/1.8/webrick/  
adding “svg” =\> “image/svg+xml”

But no matter what I try the browser recognizes it is a svg file but  
wants to just save it (indicative of a mime problem).

Can anyone solve this problem ?

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 12, 2007, 2:59pm UTC](https://www.ruby-forum.com/t/display-svg-challenge/88500/2 "2007-03-12T14:59:42Z")

</div>

Are you embedding the SVG image in HTML or serving it directly?

On 3/11/07, john [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> svg+xml in Firefox), I can only think of 2 reasons that it is not
> 
> But no matter what I try the browser recognizes it is a svg file but  
> wants to just save it (indicative of a mime problem).
> 
> Can anyone solve this problem ?
> 
> >

–  
Thanks,  
-Steve  
[http://www.stevelongdo.com](http://www.stevelongdo.com)

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 12, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/display-svg-challenge/88500/3 "2007-03-12T17:34:07Z")

</div>

well for icons - they are static svg files located in the /public/  
images folder, but graphs will be generated dynamically based on data.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 13, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/display-svg-challenge/88500/4 "2007-03-13T18:31:07Z")

</div>

thanks for info - and perhaps if .svg is added to the yml mapping to  
application/xhtml+xml it may work,  
I’ll also try this in webrick (I thought I did but will double  
check).

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 14, 2007, 1:27am UTC](https://www.ruby-forum.com/t/display-svg-challenge/88500/5 "2007-03-14T01:27:11Z")

</div>

Getting closer I think - I applied the “.svg” =\> application/xhtml  
+xml mapping to webrick httputils.rb and now I get empty scrollbars  
when trying to display a SVG icon from the /public/images folder. I  
played around with some sizes - but no luck. Any ideas ?

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 13, 2007, 1:26am UTC](https://www.ruby-forum.com/t/display-svg-challenge/88500/6 "2007-03-13T01:26:51Z")

</div>

Mongrel seems to work with embedded SVG, IF you serve the page as .xhtml  
which maps in Mongrel’s mimetypes.yml to application/xhtml+xml.

try this little chunk stolen from Sam Ruby’s (  
[application/atom+json ?](http://www.intertwingly.net/blog/2007/01/15/application-atom-json)) site:

```
<circle fill="#80a3cf" r="6.5" stroke="#FFF"/>

```

On 3/12/07, john [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > b) in httputils.rb under /usr/lib/ruby/1.8/webrick/
> 
> >

–  
Thanks,  
-Steve  
[http://www.stevelongdo.com](http://www.stevelongdo.com)
