How do I change or remove layouts from my application on a specific Rails view to allow my users to have a more enjoyable printing experience? (No navbar, or other extra data)
如何在特定的Rails视图中更改或删除应用程序中的布局,以使我的用户获得更愉快的打印体验? (没有导航栏或其他额外数据)
I have been banging my head against the table for a few hours now trying to figure this out. I have tried using render layout: false
with no success.
现在我一直在敲桌子几个小时试图解决这个问题。我尝试过使用渲染布局:false但没有成功。
I have tried creating an action like below but it didn't work for me either:
我尝试过创建一个类似下面的动作,但它对我来说也不起作用:
def print
respond_to do |format|
format.html { render layout: false }
end
end
I tried linking to this action by using the following:
我尝试使用以下方法链接到此操作:
<%= link_to 'Printer Friendly Version', product_path(@product), :action => 'print', target: '_new' %>
<%= link_to'打印机友好版本',product_path(@product),:action =>'print',target:'_ new'%>
Am I just completely off base here? How can I better approach this obstacle? I do not want to use PDF or Javascript, I just want to render printer-friendly HTML.
我刚刚离开这里吗?我怎样才能更好地应对这一障碍?我不想使用PDF或Javascript,我只想渲染打印机友好的HTML。
1 个解决方案
#1
13
You can do it just with CSS like this: See full article here.
你可以用这样的CSS做到这一点:在这里查看全文。
<style type="text/css">
@media print{
body{ background-color:#FFFFFF; background-image:none; color:#000000 }
#ad{ display:none;}
#leftbar{ display:none;}
#contentarea{ width:100%;}
}
</style>
It uses a simplified CSS when it detects that the page is being sent to the printer.
它在检测到页面被发送到打印机时使用简化的CSS。
- W3Schools链接 - 。
Also see this article:
另见本文:
Abstract: How to make printer friendly web pages
摘要:如何制作打印机友好的网页
If your web site delivers value to your audience, chances are they are going to want to print pages out. Making sure desktop printers handle your web site well is another aspect of building a great user-experience.
如果您的网站为您的受众带来了价值,那么他们可能会想要打印出来。确保桌面打印机能够很好地处理您的网站,这是构建卓越用户体验的另一个方面。
This article takes a quick look at using Cascading Style Sheets to design printed web pages.
本文将快速介绍如何使用层叠样式表来设计打印的网页。
#1
13
You can do it just with CSS like this: See full article here.
你可以用这样的CSS做到这一点:在这里查看全文。
<style type="text/css">
@media print{
body{ background-color:#FFFFFF; background-image:none; color:#000000 }
#ad{ display:none;}
#leftbar{ display:none;}
#contentarea{ width:100%;}
}
</style>
It uses a simplified CSS when it detects that the page is being sent to the printer.
它在检测到页面被发送到打印机时使用简化的CSS。
- W3Schools链接 - 。
Also see this article:
另见本文:
Abstract: How to make printer friendly web pages
摘要:如何制作打印机友好的网页
If your web site delivers value to your audience, chances are they are going to want to print pages out. Making sure desktop printers handle your web site well is another aspect of building a great user-experience.
如果您的网站为您的受众带来了价值,那么他们可能会想要打印出来。确保桌面打印机能够很好地处理您的网站,这是构建卓越用户体验的另一个方面。
This article takes a quick look at using Cascading Style Sheets to design printed web pages.
本文将快速介绍如何使用层叠样式表来设计打印的网页。