Ruby 无法使用Rails 3包含pdf的样式表文件

Ruby 无法使用Rails 3包含pdf的样式表文件,ruby,ruby-on-rails-3.2,wicked-pdf,Ruby,Ruby On Rails 3.2,Wicked Pdf,我想在Rails 3中使用wicked_PDF在生成的PDF文件中包含样式表。我在test.css文件中声明了一些样式标记,如下所示 样式表/test.css: 我还在application.html.erb文件中包含了wicked_pdf样式表路径 <!DOCTYPE html> <html> <head> <title>Generate4</title> <%= stylesheet_link_tag "appl

我想在Rails 3中使用wicked_PDF在生成的PDF文件中包含样式表。我在
test.css
文件中声明了一些样式标记,如下所示

样式表/test.css:

我还在
application.html.erb
文件中包含了wicked_pdf样式表路径

<!DOCTYPE html>
<html>
<head>
  <title>Generate4</title>
  <%= stylesheet_link_tag    "application", :media => "all" %>
  <%= wicked_pdf_stylesheet_link_tag "test" -%>
  <%= javascript_include_tag "application" %>
  <%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>

生成4
“全部”%>
但是在输出的PDF文件中没有显示样式。请检查我的其他文件

users/test.html.erb:

Hello rails
用户\u controller.rb:

class UsersControllerRails.root.join('public',“test.pdf”)
pdf=呈现字符串(pdf:“test.pdf”,模板:“users/test.html.erb”,编码:“UTF-8”)
发送数据pdf,:disposition=>'inline',文件名:'something.pdf',:type=>'application/pdf'
save_path=Rails.root.join('pdf','filename.pdf'))
打开(保存路径,'wb')do |文件|
文件“\u blank”%>

请帮助我解决此问题,并在样式表中显示带有正确声明标记的输出。

def download\u pdf
def download_pdf
  pdf = render_to_string(pdf: "test.pdf", template: "users/test.html.erb", encoding: "UTF-8", layout: 'application')
  send_data pdf ,:disposition => 'inline', filename: 'something.pdf', :type => 'application/pdf'
  save_path = Rails.root.join('pdfs','filename.pdf')
  File.open(save_path, 'wb') do |file|
    file << pdf
  end
end
pdf=呈现字符串(pdf:“test.pdf”,模板:“users/test.html.erb”,编码:“UTF-8”,布局:“application”) 发送数据pdf,:disposition=>'inline',文件名:'something.pdf',:type=>'application/pdf' save_path=Rails.root.join('pdf','filename.pdf')) 打开(保存路径,'wb')do |文件|
文件您可以为pdf@user123指定布局:您可以编辑代码以获得正确的输出吗。@user123:添加布局后,它抛出错误模板缺少模板layouts/application.css,带有{:locale=>[:en],:formats=>[:html],:handlers=>[:erb,:builder,:coffee]}。搜索:“:“C:/Site/generate4/app/views”'您应该替换css名称而不是应用程序。csslayout值应该仅为应用程序而不是应用程序。cssadd一行到application.html.erbLet。
<h1>Hello rails</h1>
class UsersController < ApplicationController
    def index

    end
    def download_pdf
         #render pdf: 'test',
           #layout: '/layouts/test',
           #template: '/users/test',
           #handlers: [:erb],
           #formats: [:pdf],
           #:save_to_file => Rails.root.join('public', "test.pdf")
           pdf = render_to_string(pdf: "test.pdf", template: "users/test.html.erb", encoding: "UTF-8")

           send_data pdf ,:disposition => 'inline', filename: 'something.pdf', :type => 'application/pdf'
           save_path = Rails.root.join('pdfs','filename.pdf')
            File.open(save_path, 'wb') do |file|
              file << pdf
            end

    end
end
<p>
    <%= link_to "Download Pdf",download_pdf_path(:format => "pdf"),:target => "_blank" %>
</p>
def download_pdf
  pdf = render_to_string(pdf: "test.pdf", template: "users/test.html.erb", encoding: "UTF-8", layout: 'application')
  send_data pdf ,:disposition => 'inline', filename: 'something.pdf', :type => 'application/pdf'
  save_path = Rails.root.join('pdfs','filename.pdf')
  File.open(save_path, 'wb') do |file|
    file << pdf
  end
end
<%= stylesheet_link_tag "test"%>