Search code examples
rubyprintinglink-to

Ruby print button


 <%= link_to "Print", 'window.print();return false;', class: "btn btn-primary" %>

Trying to implement a print button but I don't know what format to use. Could anyone help me. I want it to be using the class btn btn-primary


Solution

  • You need to tell the browser that you want to execute Javascript there. So you either need to use onClick, which can be given via a :onclick => parameter, or prefix the code with javascript:.

    Here is a similar SO question: How can I put a print link/button on my project page to printout an infomation?

    Try something like this:

    <%= link_to "Print", '#', class: "btn btn-primary", 
                onclick: 'window.print();return false;' %>