Rendering Inline SVG - Here's how.. But why?

Well, I got rails to render my inline SVG code in an rhtml file (parsed
by
ERb) in Firefox using the rest pattern. I thought all of this would
work
without the “after_filter” but for some reason, without it it doesn’t
work.
I have no idea why its needed! Can anyone explain?

Here’s how I got it to work…:

Environment.rb:
Add the following:
Mime::Type.register “application/xhtml+xml”, :svg

location_controller.rb (Or whatever your restful controller is!)
def index
@locations = Location.find(:all)
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @locations.to_xml }
format.svg { render :action => “svg.rhtml”, :layout => false }
end
end

also add:

after_filter :set_content_type
def set_content_type
if ( @request.env[‘HTTP_ACCEPT’].match(/application/xhtml+xml/))
@headers[‘Content-Type’] = “application/xhtml+xml; charset=utf-8”
end
end

Now create a file called svg.rhml in your views folder and paste the
following:

SVG within XHTML Demo

You can embed SVG into XHTML, provided that your browser natively implements SVG. E.g. Firefox 1.5 supports most of static SVG.

The SVG part starts below



HELLO cher visiteur


The SVG part ended above

Voila! It works… Now why do I need the before filter!

Thanks :stuck_out_tongue_winking_eye:
-RR

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs