How to print a page in Rails / HTML?

Viewed 979

enter image description hereI'm not sure if it's related to Rails, JavaScript or more just to some basic old HTML code.

I have a simple web app I've built with Ruby on Rails with a navbar and a sidebar at:

layout > application.html.erb

And the actual page (<%= yield %>) in the middle (classic bootstrap style I copied from bootstrap main example).

How can I add a simple Print button that lets the user print just the the actual page that the button is located at (without the navbar and sidebar)?

1 Answers

here you can use

<%= link_to 'print', 'your_link_here', :onclick => 'window.print();return false;'%>

use below to hide contents you don't want to print :-

@media print {
  div.sidebar, div.navbar {
    display: none;
  }
}
Related