我为Rails 4应用创建了一个仅打印模板和样式表。一切都在我的本地环境中很好用,但在生产中(在Heroku上),视图找不到样式表。我试过了rake assets:precompile
,这似乎也没有帮助。另外 - 如果可能 - 我想从所有其他视图中排除此样式表。有什么想法吗?
def print
@purchase_request = PurchaseRequest.find(params[:id])
render :layout => "print"
end
/views/purchase_requests/print.html.erb
<p>
Purchase Request
</p>
<table>
# I have omitted the table data in the interest of brevity
</table>
/views/layouts/print.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Depot</title>
<%= stylesheet_link_tag "print", media: :all %>
</head
<body>
<div id="wrapper">
<%= yield %>
</div>
</body>
</html>
/assets/stylesheets/print.css.scss(不是必需的,但为了完整性)
table {
border: 2px solid #000;
width: 100%;
border-collapse: collapse;
td {
border-top: 2px solid #000;
padding: .5em;
}
td.key, td.signature_key {
border-right: 2px solid #000;
font-weight: bold;
}
td.signature_key, td.signature_blank {
padding: 2em;
}
}
p {
width: 100%;
text-align: center;
font-size: 1.5em;
font-weight: bold;
}
答案 0 :(得分:3)
确保您已关注Heroku guideline for Rails 4。
仅当您将gem 'rails_12factor', group: :production
添加到Gemfile时,它才会预编译资产。
<强>更新强>
您还需要将print.css包含在 environment / production.rb 文件中:
config.assets.precompile += %w( print.css)