Rails如何解决错误文件名太长@ rb_sysopen

时间:2017-10-26 20:36:06

标签: ruby-on-rails ruby-on-rails-4

我有一个应用程序,我可以生成报告,当我尝试生成一个时,我有这个错误错误文件名太长@ rb_sysopen和很长的东西见下文。我想了解这个错误的原因是什么。我该看什么?

Errno::ENAMETOOLONG at /study_versions/2/export_acrf.2
File name too long @ rb_sysopen - /Users/jakublemiszewski/Desktop/A3informatics/Tourmalet/Tourmalet/public/<html><head><style>h1 { font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 24pt; line-height: 34pt; }
h1.title { font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 24pt; line-height: 30pt; text-align: center; margin-top: 0; }
h2 { font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 18pt; line-height: 28pt; }

错误消息中的许多行都会继续。

但是,我不知道在哪里看,我花了几个小时才能理解,却找不到解决方案。

我认为错误来自这个类:

class PdfReport

  C_CLASS_NAME = "PdfReport"

  def self.create(title, sub_title, user, body_html)
    paper_size = "A4"
    html = page_header()
    html += title_page(title, sub_title, user)
    # Document history
    html += body_html
    # Completion instructions
    html += page_footer()
    #ConsoleLogger.log(C_CLASS_NAME, "create", "HTML=" + html.to_s)
    # pdf = WickedPdf.new.pdf_from_string(html, :page_size => paper_size, :footer => {:font_size => "10", :font_name => "Arial, \"Helvetica Neue\", Helvetica, sans-serif", :left => "", :center => "", :right => "[page] of [topage]"} )
    cls = [{:status=> ["created", "no_change", "updated"], :prefered_term => "test term", :notation => "This is test notation" }]
    results = [{ bc_demo: 'demo'}]
    pdf = CdiscChangesReport.new.create(results, cls, User.last, html)
    return pdf
  end

  def self.page_header
    html = "<html><head>"
    html += "<style>"
    html += "h1 { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 24pt; line-height: 34pt; }\n"
    html += "h1.title { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 24pt; line-height: 30pt; text-align: center; margin-top: 0; }\n"
    html += "h2 { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 18pt; line-height: 28pt; }\n"
    html += "h2.title { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 18pt; line-height: 24pt; text-align: center; margin-top: 0; }\n"
    html += "h3 { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 16pt; }\n"
    html += "h4 { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 14pt; }\n"
    html += "h5 { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 12pt; }\n"
    html += "p { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; }\n"
    html += "table tr td { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; text-align: left; vertical-align: top; padding: 5px;}\n"
    html += "table.simple { border: 1px solid black; border-collapse: collapse; width: 100%;}\n"
    html += "table.simple tr td { border: 1px solid black; font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; text-align: left; vertical-align: top; padding: 5px;}\n"
    html += "table.simple tr th { border: 1px solid black; font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; text-align: left; vertical-align: top; padding: 5px;}\n"
    html += "table.form_table { border: 1px solid black; width: 100%;}\n"
    html += "table.form_table tr td { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; text-align: left; vertical-align: top; padding: 5px;}\n"
    html += "table.form_table h4 { vertical-align: middle;}\n"
    html += "table.form_table td:first-child{ font: bold; }\n"
    html += "table.form_repeat { border: 1px solid black; width: 100%;}\n"
    html += "table.form_repeat th { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; text-align: left; vertical-align: top; }\n"
    html += "table.form_repeat tr td { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; text-align: left; vertical-align: top;}\n"
    html += "table.details tr td { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 11pt; text-align: left; vertical-align: top; padding: 1px; }\n"
    html += "table.ci { border: 1px solid black; width: 100%; border-collapse: collapse;}\n"
    html += "table.ci tr td { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; text-align: left; vertical-align: top; padding: 5px; border-bottom: 1pt solid black; }\n"
    html += ".ci td table, .ci td table tbody, .ci td table td { border:none; }\n" # Stops inheritence into markdown
    html += "table.note { border: 1px solid black; width: 100%;}\n"
    html += "table.note tr td { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; font: bold; text-align: left; vertical-align: top; }\n"
    html += "table.input_field { border-left: 1px solid black; border-right: 1px solid black; border-bottom: 1px solid black;}\n"
    html += "table.input_field tr td { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 8pt; text-align: center; vertical-align: center; padding: 5px; }\n"
    html += "table.input_field td:not(:last-child){border-right: 1px dashed}\n"
    html += "table.cl_field tr td { font-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif; font-size: 10pt; text-align: left; vertical-align: center; padding: 2px; }\n"
    html += "table.cl_field td:first-child{ border: 1px solid black; }\n"
    html += "tr.warning { background-color: #fcf8e3 !important; }\n"
    html += "</style>"
    html += "</head><body>"
    return html
  end

  def self.page_footer
    html = "</body></html>"
    return html
  end

  def self.title_page(title, sub_title, user)
    name = ENV['organization_title']
    image_file = ENV['organization_image_file']
    dir = Rails.root.join("app", "assets", "images")
    file = File.join(dir, image_file)
    time_generated = Time.now
    # Generate HTML
    html = "<br><br><div style=\"text-align: center;\"><img src=\"#{file}\" style=\"height:75px;\"></div>"
    html += "<h2 class=\"title\">#{name}</h2>"
    html += "<br>" * 10
    html += "<h1 class=\"title\">#{title}<br>#{sub_title}</h1>"
    html += "<br>" * 23
    html += "<table class=\"details\" align=\"right\"><tr><td>Run at:</td><td>#{time_generated.strftime("%Y-%b-%d, %H:%M:%S")}</td></tr><tr><td>Run by:</td><td>#{user.email}</td></tr></table>"
    html += page_break
    return html
  end

  def self.page_break
    return "<p style='page-break-after:always;'></p>"
  end

end 

1 个答案:

答案 0 :(得分:0)

文件系统对文件名路径的长度有限制。您的错误显示您使用文件内容命名文件,这可能就是您达到此限制的原因。

根据您的错误消息,这是您尝试过的文件名:

/Users/jakublemiszewski/Desktop/A3informatics/Tourmalet/Tourmalet/public/<html><head><style>h1 { font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 24pt; line-height: 34pt; }
h1.title { font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 24pt; line-height: 30pt; text-align: center; margin-top: 0; }
h2 { font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 18pt; line-height: 28pt; }

为您的文件指定正确的名称可以解决您的问题。