David Kahn
2010-Oct-29 18:03 UTC
Asking Rails 3 to render a pdf from a file but getting template error instead
Why is Rails looking for a template while I have told it to render a specific file? This worked under Rails 2. I read http://www.engineyard.com/blog/2010/render-options-in-rails-3/ which from I gather makes any format.xxx look for a template xxx which is *not* what I need to do as the file is created dynamically: In my controller: pdf_file_path = "./directory/file_name.pdf" # just an example, assume this file exists respond_to do |format| format.pdf { render :file => pdf_file_path } end But I get: ActionView::MissingTemplate (Missing template comparisons/display with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:pdf], :locale=>[:en, :en]} in view paths "/Users/DK/Documents/ror/projects/creditcompare3/app/views"): Is there a way / better way to do this? -- 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.
Michael Pavling
2010-Oct-29 18:22 UTC
Re: Asking Rails 3 to render a pdf from a file but getting template error instead
On 29 October 2010 19:03, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> Why is Rails looking for a template while I have told it to render a > specific file? This worked under Rails 2. I read > http://www.engineyard.com/blog/2010/render-options-in-rails-3/ which from I > gather makes any format.xxx look for a template xxx which is *not* what I > need to do as the file is created dynamically:I think you misunderstand that article. Looks to me that instead of passing css filenames into the "ActionController.add_renderer" block, you could just as easily pass your actual dynamically generated PDF, and then have the "send_data" call send your file. But I agree, it''s certainly easier the just "render :file => foo_bar" - which I do in some of my controller actions, and I''ve not moved to Rails3 yet, so I''ll be interested in your result. -- 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.
Rob Biedenharn
2010-Oct-29 20:34 UTC
Re: Asking Rails 3 to render a pdf from a file but getting template error instead
On Oct 29, 2010, at 2:03 PM, David Kahn wrote:> Why is Rails looking for a template while I have told it to render a > specific file? This worked under Rails 2. I read http://www.engineyard.com/blog/2010/render-options-in-rails-3/ > which from I gather makes any format.xxx look for a template xxx > which is *not* what I need to do as the file is created dynamically: > > In my controller: > > pdf_file_path = "./directory/file_name.pdf" # just an example, > assume this file exists > respond_to do |format| > format.pdf { render :file => pdf_file_path } > end > > But I get: > > ActionView::MissingTemplate (Missing template comparisons/display > with > {:handlers > = > > > [:erb > , :rjs > , :builder, :rhtml, :rxml], :formats=>[:pdf], :locale=>[:en, :en]} > in view paths "/Users/DK/Documents/ror/projects/creditcompare3/app/ > views"): > > Is there a way / better way to do this?I think that you''re looking for either send_file or send_data depending on how you create the PDF. If there actually is a file, then send_file will be what you want. If you still have the data in memory, then send_data(stuff) is similar to render(:text => stuff) -Rob Rob Biedenharn Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Oct-30 22:54 UTC
Re: Asking Rails 3 to render a pdf from a file but getting template error instead
On Fri, Oct 29, 2010 at 1:22 PM, Michael Pavling <pavling-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 29 October 2010 19:03, David Kahn <dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote: > > Why is Rails looking for a template while I have told it to render a > > specific file? This worked under Rails 2. I read > > http://www.engineyard.com/blog/2010/render-options-in-rails-3/ which > from I > > gather makes any format.xxx look for a template xxx which is *not* what I > > need to do as the file is created dynamically: > > I think you misunderstand that article. > > Looks to me that instead of passing css filenames into the > "ActionController.add_renderer" block, you could just as easily pass > your actual dynamically generated PDF, and then have the "send_data" > call send your file. >Thanks Michael and Rob - you got me through this. The following works: send_file "#{TEMP_DIRECTORY}/#{comparison.id}_#{params[:view]}.pdf", :stream => false, :type => ''application/pdf'', :disposition => ''inline''> But I agree, it''s certainly easier the just "render :file => foo_bar" >Right. I know there must be a good reason for a lot of these changes and at some point it will all come together the ponies and rainbows will appear. I am waiting semi-patiently for this moment :)> - which I do in some of my controller actions, and I''ve not moved to > Rails3 yet, so I''ll be interested in your result. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.