【问题标题】:Print only Stylesheet on Heroku在 Heroku 上仅打印样式表
【发布时间】:2013-10-11 21:19:10
【问题描述】:

我为我的 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;
}

【问题讨论】:

    标签: ruby-on-rails heroku asset-pipeline


    【解决方案1】:

    确保您已关注Heroku guideline for Rails 4

    仅当您将 gem 'rails_12factor', group: :production 添加到 Gemfile 时,它​​才会预编译资产。

    更新

    您还需要将 print.css 包含到您的 environments/production.rb 文件中:

    config.assets.precompile += %w( print.css)
    

    【讨论】:

    • 是的,包括在内。资产在其他任何地方都可以正常工作 - 只有打印布局有问题。
    • 您还需要将 print.css 包含到您的环境/production.rb 文件中:config.assets.precompile += %w( print.css)
    猜你喜欢
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-07
    相关资源
    最近更新 更多