# Print Layout

**URL:** <https://www.ruby-forum.com/t/print-layout/143429>\
**Category:** Rails\
**Created:** [July 18, 2008, 1:13pm UTC](https://www.ruby-forum.com/t/print-layout/143429 "2008-07-18T13:13:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![se\_pavel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@se\_pavel](https://www.ruby-forum.com/u/se_pavel)\
**Post date:** [July 18, 2008, 1:13pm UTC](https://www.ruby-forum.com/t/print-layout/143429/1 "2008-07-18T13:13:38Z")

</div>

Hello All,

We have developed the following code in application.rb

def determine\_layout  
if !params[:layout].blank? and params[:layout] == “print”  
@layout = “print”  
else  
@layout = “public”  
@layout = “admin” if params[:controller] =~ /admin/  
end  
return @layout  
end

This code allows us to use link with param in URL “layout=print”, so  
the user can preview any page in browser without the menu, header,  
footer and etc,

in this project we have only 2 layouts, but there are project where we  
have 30 - 40 layouts,  
does anybody know how to write this function in best way like

def determine\_layout  
if !params[:layout].blank? and params[:layout] == “print”  
@layout = “print”  
else  
\*\*\* by default in controllers \*\*\*  
end  
return @layout  
end

Regards,  
Pavel

---

<div class="post-metadata">

**Author:** ![se\_pavel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@se\_pavel](https://www.ruby-forum.com/u/se_pavel)\
**Post date:** [July 18, 2008, 2:29pm UTC](https://www.ruby-forum.com/t/print-layout/143429/2 "2008-07-18T14:29:11Z")

</div>

Hi Pavel,

se\_pavel wrote:

> This code allows us to use link with param in URL  
> “layout=print”, so the user can preview any page in  
> browser without the menu, header, footer and etc,

The easiest way of doing this is with CSS. You have a separate  
stylesheet  
for print media with the items you don’t want displayed set to ‘display:  
none;’.

HTH,  
Bill
