Hi you all, I''ve used the library SVG::Graph to generate SVG images. I have this code in the controller: respond_to do |format| format.html format.xml { render :xml => @graphic.to_svg} end When html, I display a jpg graph. When XML, I make the graphic with SVG::Graph and the xml appears. To see this SVG graph, I can store the resulting XML file from my browser, renaming it with the .svg extension, and clicking on the resulting file (I have the adobe plugin to see SVG images). This is tedious, and this is why I''ve added the following in the controller: format.svg { render :xml => @graphic.to_svg} And the following in environment.rb: Mime::Type.register "image/svg+xml", :svg But this does not display the image directly; it stills renders an XML file. What should I do? Thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 19 Feb 2008, at 12:22, Damaris Fuentes wrote:> I''ve used the library SVG::Graph to generate SVG images. > I have this code in the controller: > > respond_to do |format| > format.html > format.xml { render :xml => @graphic.to_svg} > end > > When html, I display a jpg graph. > When XML, I make the graphic with SVG::Graph and the xml appears. > > To see this SVG graph, I can store the resulting XML file from my > browser, renaming it with the .svg extension, and clicking on the > resulting file (I have the adobe plugin to see SVG images). > > This is tedious, and this is why I''ve added the following in the > controller: > format.svg { render :xml => @graphic.to_svg} > > And the following in environment.rb: > Mime::Type.register "image/svg+xml", :svg > > But this does not display the image directly; it stills renders an XML > file. > What should I do? Thanks.I believe you''ll need to set the content type header so that the browser knows you''re serving svg: format.xml do headers["Content-Type"] = "''image/svg+xml; charset=utf-8" render :xml => @graphic.to_svg end That might need to be "@headers" and you may need to leave out "; charset=utf-8" Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Peter, no, it does not work. I''ve added: headers["content-type"] = "image/svg+xml" and what happens is that when accesing, I received a message if I want to open or save the file "graphic.svg" (it is not displayed directly in the browser). It does not matter what I do, but the file is never open or saved, cause it does not exist ( because it is not a file stored in the server, i''m afraid). Peter De Berdt wrote:> On 19 Feb 2008, at 12:22, Damaris Fuentes wrote: > >> >> >> But this does not display the image directly; it stills renders an XML >> file. >> What should I do? Thanks. > > I believe you''ll need to set the content type header so that the > browser knows you''re serving svg: > > format.xml do > headers["Content-Type"] = "''image/svg+xml; charset=utf-8" > render :xml => @graphic.to_svg > end > > That might need to be "@headers" and you may need to leave out "; > charset=utf-8" > > > Best regards > > Peter De Berdt-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I got it! I''ve used the method for sending other data, so: format.svg { send_data(@graphic.to_svg, :type=>"image/svg+xml", :disposition =>"inline") } Thanks. Damaris Fuentes wrote:> Hi Peter, > no, it does not work. > I''ve added: headers["content-type"] = "image/svg+xml" > > and what happens is that when accesing, I received a message if I want > to open or save the file "graphic.svg" (it is not displayed directly in > the browser). It does not matter what I do, but the file is never open > or saved, cause it does not exist ( because it is not a file stored in > the server, i''m afraid). > > Peter De Berdt wrote: >> On 19 Feb 2008, at 12:22, Damaris Fuentes wrote: >> >>> >>> >>> But this does not display the image directly; it stills renders an XML >>> file. >>> What should I do? Thanks. >> >> I believe you''ll need to set the content type header so that the >> browser knows you''re serving svg: >> >> format.xml do >> headers["Content-Type"] = "''image/svg+xml; charset=utf-8" >> render :xml => @graphic.to_svg >> end >> >> That might need to be "@headers" and you may need to leave out "; >> charset=utf-8" >> >> >> Best regards >> >> Peter De Berdt-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---