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:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:svg="http://www.w3.org/2000/svg">
<head>
<title>SVG within XHTML Demo</title>
</head>
<body>
<p> You can embed SVG into XHTML, provided that your browser natively
implements
SVG. E.g. Firefox 1.5 supports most of static SVG.
</p>
The SVG part starts below <hr />
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="400"
height="300">
<!-- un petit rectangle avec des coins arroundis -->
<rect x="50" y="50" rx="5" ry="5"
width="300" height="100"
style="fill:#CCCCFF;stroke:#000099"/>
<!-- un texte au meme endroit -->
<text x="55" y="90"
style="stroke:#000099;fill:#000099;font-size:24;">
HELLO cher visiteur
</text>
</svg>
<hr />
The SVG part ended above
</body>
</html>
Voila! It works.. Now why do I need the before filter!
Thanks ;P
-RR
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---