开发者

pdfkit send_data

开发者 https://www.devze.com 2023-03-18 02:55 出处:网络
I\'m trying to send pdf to user. For example if user is in /products?category_id=3he has to get report of products whose category id is 3 not all reports. I couldn\'t find a way to pass parameter. How

I'm trying to send pdf to user. For example if user is in /products?category_id=3 he has to get report of products whose category id is 3 not all reports. I couldn't find a way to pass parameter. How can i do this ?

products_controller

def index
   @products Product.where("category_id = ?", params[:category_id)
end  

def reporter 
   kit = PDFKit.new(render_to_string(:action => "products/index", :layout => "report"))
  开发者_开发问答 send_data(kit.to_pdf, :type => :pdf) 
end

My view is like this

<% @products.each do |product| %>
<%= product.name %>
<% end %>

<%= link_to "Download(PDF)", reporter_path, :method => :post %>
0

精彩评论

暂无评论...
验证码 换一张
取 消