I am using Rails for my application(student register) and i need a print link/button to print out some student's information. Please what do I do?
You can use this tag to make a print link.
<%= link_to 'print', 'your_link_here', :onclick => 'window.print();return false;'%>
Now, if you want to print a specific section, you can use media types of css
/*This css will only works when you print*/
@media print {
body {
background: #FFF;
}
}
I'm not sure if i misunderstand something here because this seems more like a javascript question then a rails one to me: But here is how you make a print link:
<a href="#" onclick="window.print();return false;">print me</a>
Note: the return false
is critical, otherwise the app will hung up.
You could also make a special print page with only the desired information and have window.print in the onload event like this:
<body onload="window.print();">
Include this in where you want to add the print button
function printPage() {
window.print()
}
After that, give a link or button
<%= link_to "print", "#", onclick: "printPage()" %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With