Forum: Ruby on Rails How to print a page using RJS

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B8ac655007757eafd492a3c519f19d33?d=identicon&s=25 Manisha Tripathy (manisha)
on 2009-06-04 11:41
Hello everyone,

I am trying to add an option to print my view, i.e the display webpage
in my Rails application.At present I am using HTML DOM for that but I
want to do that in ruby.Following some online tutorials, I am trying to
use rjs for that. the codes are some thing like this

 # view.rhtml

<%=link_to_remote ("Print Page", :url => {:action => :print})%><br />

# doc.rjs

page.hide 'header'
page.hide 'header2'

page.<<'javascript:window.open();'

page.show 'header'
page.show 'header2'

Can anyone give some idea as to why this is not working?I have very less
knowledge in this.Is there any other way to do the same?
C4eb02ef0d5e1474bbfe5be14ed6adf8?d=identicon&s=25 Rakoth (Guest)
on 2009-06-04 12:21
(Received via mailing list)
Hi, Manisha Tripathy.

You can solve this problem by creating special css for printer,

<%= stylesheet_link_tag "print_style", :media => "print" %>

and in print_style.css

#header{
  display:none;
}
and so on..

On Jun 4, 1:41 pm, Manisha Tripathy <rails-mailing-l...@andreas-s.net>
B8ac655007757eafd492a3c519f19d33?d=identicon&s=25 Manisha Tripathy (manisha)
on 2009-06-04 14:30
Ok but in that case , I think we will not be using rjs file. right?
Can you just explain a bit more please.

Rakoth wrote:
> Hi, Manisha Tripathy.
>
> You can solve this problem by creating special css for printer,
>
> <%= stylesheet_link_tag "print_style", :media => "print" %>
>
> and in print_style.css
>
> #header{
>   display:none;
> }
> and so on..
>
> On Jun 4, 1:41�pm, Manisha Tripathy <rails-mailing-l...@andreas-s.net>
C4eb02ef0d5e1474bbfe5be14ed6adf8?d=identicon&s=25 Rakoth (Guest)
on 2009-06-04 15:28
(Received via mailing list)
Yes, in this case you just add css tag to page that you want to print.
This css will be used when you run print command in your browser,
becouse parameter :media set to "print".
And you can specify look of a page when printed using the appropriate
styles, for exalple to hide
element with id="header" or with class="navigation" use

#header, .navigation{
  display:none;
}

Try to find more information on this topic using google query "css
media print"

forgive me my english, I`m using google translate.


On Jun 4, 4:30 pm, Manisha Tripathy <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.