ruby - How do I download a pdf document from html in rails for a custom path? -


i trying figure out how download pdf document standard html template. using wicked pdf gem generate pdf.

i followed instructions in bundle install , set config according https://github.com/mileszs/wicked_pdf

following this, trying make work custom route. keeps rendering html instead of delivering pdf specified in form

what doing wrong? there better way route pdf download?

config/routes.rb

  match "/profile" => "vacancies#profile", via: :get 

view

<%= form_for(@vacancy, :url => profile_path, :html => {:method => :get, :format => 'pdf'}) |f| %>   <%= submit_tag "export profile"%> <%end%> 

vacancies_controller

def profile   respond_to |format|      format.html{        render :layout => false      }      format.pdf        render :pdf => "temp"        render :layout => false      end   end end 

i wrote second action following research, download link(in view) works

  def download       html = render_to_string(:action => :resume, :layout => false)       pdf = wickedpdf.new.pdf_from_string(html)       send_data(pdf,           :filename    => "temp.pdf",           :disposition => 'attachment')    end 

config/routes.rb

match "/download_profile" => "vacancies#download", via: :get 

view

<%= link_to "export profile", download_profile_path"%> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -