Michael Schuerig
2010-Jul-03 17:02 UTC
Renderer: rendering to *another* format inside a renderer
My skeletal renderer looks like this ActionController.add_renderer :pdf do |template, options| html = render_to_string(template, options) ... end The trouble here is that render_to_string looks for a template for MIME type PDF, e.g. show.pdf.erb. Unfortunately, that''s not what I want. I need to get HTML. I haven''t found a straightforward option to achieve this. html = render_to_string(options.merge( :template => "#{template}.html") That''s not pretty, but gets me halfway there. However, when I call render :pdf => ''show'', :layout => ''print'' the layout is passed through to render_to_string, but ignored. If I rename layouts/print.html.erb to layouts/print.pdf.erb, it works as long as all partials used by that layout are available in pdf variants, too. Now, I see that this behavior might be useful most of the time, but this time it is exactly not what I want. Is there a *clean* way to make render_to_string do what I want? Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jul-03 18:44 UTC
Re: Renderer: rendering to *another* format inside a renderer
Michael Schuerig wrote:> My skeletal renderer looks like this > > ActionController.add_renderer :pdf do |template, options| > html = render_to_string(template, options) > ... > end > > The trouble here is that render_to_string looks for a template for MIME > type PDF, e.g. show.pdf.erb. Unfortunately, that''s not what I want. I > need to get HTML.WTF? What problem are you trying to solve that means you need to serve HTML when a PDF file is requested? I don''t see how that can ever be the right thing to do. -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Schuerig
2010-Jul-03 20:18 UTC
Re: Renderer: rendering to *another* format inside a renderer
On Saturday 03 July 2010, Marnen Laibow-Koser wrote:> Michael Schuerig wrote: > > My skeletal renderer looks like this > > > > ActionController.add_renderer :pdf do |template, options| > > > > html = render_to_string(template, options) > > ... > > > > end > > > > The trouble here is that render_to_string looks for a template for > > MIME type PDF, e.g. show.pdf.erb. Unfortunately, that''s not what I > > want. I need to get HTML. > > WTF? What problem are you trying to solve that means you need to > serve HTML when a PDF file is requested? I don''t see how that can > ever be the right thing to do.I''m passing the HTML into an HTML-to-PDF converter. wkhtmltopdf in my case. wicked_pdf does the same, but it works by alias_chain-ing render, which I''d like to avoid. Instead, I''m defining a renderer. See http://www.engineyard.com/blog/2010/render-options-in-rails-3/ Michael -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.