title: Rails How to resolve Error File name too long @ rb_sysopen
body: <p>I have an app where I can generate reports and when I'm trying to generate one I have this error Error File name too long @ rb_sysopen and a very long stuff see below. What I want to understand what could be the reason of this error. What should I look? </p>
  
  <pre><code>Errno::ENAMETOOLONG at /study_versions/2/export_acrf.2
  File name too long @ rb_sysopen - /Users/jakublemiszewski/Desktop/A3informatics/Tourmalet/Tourmalet/public/&lt;html&gt;&lt;head&gt;&lt;style&gt;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; }
  </code></pre>
  
  <p>This continues for many rows in the error message.</p>
  
  <p>However, I have no idea where to look I spent hours to understand and cannot see a solution for it.</p>
  
  <p>I believe the error comes from this class:</p>
  
  <pre><code>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 =&gt; paper_size, :footer =&gt; {:font_size =&gt; "10", :font_name =&gt; "Arial, \"Helvetica Neue\", Helvetica, sans-serif", :left =&gt; "", :center =&gt; "", :right =&gt; "[page] of [topage]"} )
      cls = [{:status=&gt; ["created", "no_change", "updated"], :prefered_term =&gt; "test term", :notation =&gt; "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 = "&lt;html&gt;&lt;head&gt;"
      html += "&lt;style&gt;"
      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 += "&lt;/style&gt;"
      html += "&lt;/head&gt;&lt;body&gt;"
      return html
    end
  
    def self.page_footer
      html = "&lt;/body&gt;&lt;/html&gt;"
      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 = "&lt;br&gt;&lt;br&gt;&lt;div style=\"text-align: center;\"&gt;&lt;img src=\"#{file}\" style=\"height:75px;\"&gt;&lt;/div&gt;"
      html += "&lt;h2 class=\"title\"&gt;#{name}&lt;/h2&gt;"
      html += "&lt;br&gt;" * 10
      html += "&lt;h1 class=\"title\"&gt;#{title}&lt;br&gt;#{sub_title}&lt;/h1&gt;"
      html += "&lt;br&gt;" * 23
      html += "&lt;table class=\"details\" align=\"right\"&gt;&lt;tr&gt;&lt;td&gt;Run at:&lt;/td&gt;&lt;td&gt;#{time_generated.strftime("%Y-%b-%d, %H:%M:%S")}&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Run by:&lt;/td&gt;&lt;td&gt;#{user.email}&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;"
      html += page_break
      return html
    end
  
    def self.page_break
      return "&lt;p style='page-break-after:always;'&gt;&lt;/p&gt;"
    end
  
  end 
  </code></pre>