My app is creating a PDF in my app''s public directory. When the visitor clicks a button, I need to be able to display the file in a new window. I cannot figure out how to do it. Any help is greatly appreciated. Thanks, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
If it''s a link, just add target="_blank" to the a tag. If it''s Javascript, there''s window.open(url, options*) IIRC. Jason On 11/15/06, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> > My app is creating a PDF in my app''s public directory. When the visitor > clicks a button, I need to be able to display the file in a new window. I > cannot figure out how to do it. Any help is greatly appreciated. > > Thanks, > Bill > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jason Roelofs wrote:> If it''s a link, just add target="_blank" to the a tag. If it''s > Javascript, > there''s window.open(url, options*) IIRC. > > JasonDo you define the Content-Type of your page ? -- 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 -~----------~----~----~----~------~----~------~--~---
Guest wrote:> Do you define the Content-Type of your page ?No. Do I need to? This is the first time I''ve tried to display anything other than HTML from a Rails app. I''m feeling really lost. Thanks, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Quickly, Here''s an example of some code in a view to set up a link that will open up a new window to receive a PDF: <%= link_to(''Forms and Endorsements'', {:action => ''show_company_terms'', :id => company.id}, :popup => [ ''terms_and_conditions'', ''width=800, height=700, left = 450, top = 100, resizable, scrollbars=yes'' ]) %> This makes a popup window named ''terms_and_conditions''. If you wanted the content to show up in the window, the action ''show_company_terms'' would need to use the send_file() helper to send back a PDF file. In the parameters for send_file, you would specify the content-type. Hope this helps. Let me know if you need more info. Wes Bill Walton wrote:> Guest wrote: > >> Do you define the Content-Type of your page ? > > No. Do I need to? This is the first time I''ve tried to display > anything > other than HTML from a Rails app. I''m feeling really lost. > > Thanks, > Bill-- 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 -~----------~----~----~----~------~----~------~--~---
Wes Gamble wrote:> Here''s an example of some code in a view > to set up a link that will open up a new window > to receive a PDF:<snip>> Hope this helps.That was a huge help. Thank you, Wes!> Let me know if you need more info.Well... since you asked ;-) I really need to (visually) use a button rather than a link. The problem is that button_to uses POST and so the :popup option doesn''t work. Any suggestions? Thanks again, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
There is no option to that. One possibility is to make a custom button. On 11/16/06, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> > > Wes Gamble wrote: > > > Here''s an example of some code in a view > > to set up a link that will open up a new window > > to receive a PDF: > <snip> > > Hope this helps. > > That was a huge help. Thank you, Wes! > > > Let me know if you need more info. > > Well... since you asked ;-) I really need to (visually) use a button > rather > than a link. The problem is that button_to uses POST and so the :popup > option doesn''t work. Any suggestions? > > Thanks again, > Bill > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill, My app. displays one of several PDFs depending on what is requested. The view has a <FORM> tag with no attributes to allow the submission attributes to be fully dynamic. Buttons invoke a Javascript function to set up the form, submit it via an AJAX request that populates the popup window with the PDF. The onSuccess code for the AJAX request hides the AJAX wait message and graphic and then evals some Javascript returned from the action that does whatever you want in the popup. In my case, it causes the popup to do a redirect to an action which will render the PDF (I couldn''t figure out a simpler way to do it). Currently, I''m using it to render 3 different PDFs. 1) View with button: <%= button_to_function(''Save and Print Insured Forms'', "submit_form_to_popup(this.form, ''print_application_window'', ''print_application'')", :style => "width: 200px;") %> 2) Javascript function submit_form_to_popup: /* Takes a form object, a popup target name, and an action for the form. AJAX-y wait graphic provided by default. */ function submit_form_to_popup(form, popup_window_name, action) { form.action = action; popup = window.open('''', popup_window_name, ''width=800, height=700, left = 450, top = 50, resizable, scrollbars=yes''); wait_image_url = window.location.protocol + ''//'' + window.location.host + ''/images/indicator_verybig.gif''; //Create a DIV in the popup window and populate it with the AJAX wait message and graphic. newDiv = popup.document.createElement(''div''); newDiv.id = ''pdf''; newDiv.style.marginTop = ''33%''; newDiv.style.textAlign = ''center''; newDiv.innerHTML = ''Please wait while your forms are generated...<br/><br/>''; wait_img = popup.document.createElement(''img''); wait_img.src = wait_image_url; newDiv.appendChild(wait_img); popup.document.body.appendChild(newDiv); //Submit the form asynchronously and execute Javascript returned from the action. new Ajax.Request(form.action, { asynchronous: true, method: ''post'', parameters: Form.serialize(form), evalScripts: true, onSuccess: function(request) {newDiv.innerHTML = ''''; eval(request.responseText);} }); return false; } 3) Rails action that is the target of the AJAX request: def print_application #Create pdfgen object here ... render :update do |page| page.assign(''popup.location.href'', url_for(:action => ''render_pdf'', :filename => pdfgen.output_file)) page.replace_html(''notice'', ''The application was saved successfully.'') end end def render_pdf send_file(params[:filename], :type => ''application/pdf'', :disposition => ''inline'') end Hope this helps, Wes -- 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 -~----------~----~----~----~------~----~------~--~---