2013-10-11 36 views
2

我創建了一個唯一的打印模板和樣式表對我的Rails應用程序4。一切都在我的本地環境的偉大工程,但在生產中(在Heroku)的觀點無法找到樣式表。我曾嘗試rake assets:precompile,而且似乎並沒有幫助的。另外 - 如果可能的話 - 我想從所有其他視圖中排除此樣式表。有任何想法嗎?僅打印樣式表在Heroku

在我的購買請求控制器

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; 
} 

回答

3

確保您遵循了Heroku guideline for Rails 4

只有當你添加gem 'rails_12factor', group: :production到您的Gemfile它會預編譯的資產。

UPDATE

您需要包括print.css你環境/ production.rb文件還:

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

是的,這是包括在內。資產做工精細其他地方 - 它僅僅是有困難的打印佈局。 – drewwyatt

+0

您還需要在您的environments/production.rb文件中包含print.css:config.assets.precompile + =%w(print.css) – alex