title: Attaching AXLSX view to mail Rails Mailer
body: <p>According to the <a href="https://github.com/straydogstudio/axlsx_rails" rel="nofollow">GitHub Page</a> for the <code>axlsx</code> gem I should use this syntax to render a xlsx view to a file and attach it:</p>
  
  <pre><code>xlsx = render_to_string handlers: [:axlsx], formats: [:xlsx], template: "users/export", locals: {users: users}
  attachments["Users.xlsx"] = {mime_type: Mime::XLSX, content: xlsx}
  </code></pre>
  
  <p>Here is my mail method:</p>
  
  <pre><code>xlsx = render_to_string(handlers: [:axlsx], formats: [:xlsx], template: 'v1/reports/reportxyz', params: {start_date: '2016-09-12', period: 'weekly'})
  attachments["report.xlsx"] = {content: xlsx, mime_type: Mime::XLSX}
  mail(to: "my@email.address", subject: "Report", format: "text")
  </code></pre>
  
  <p>However I get this error when I try and call the mailer method:</p>
  
  <pre><code>ActionView::MissingTemplate: Missing template layouts/mailer with {:locale=&gt;[:en], :formats=&gt;[:xlsx], :variants=&gt;[], :handlers=&gt;[:axlsx]}. Searched in:
    * "path/to/project/app/views"
  </code></pre>
  
  <p>Why is the <code>render_to_string</code> method affecting what the mailer view the mailer is trying to render? locgially I don't have a <code>mailer.xlsx.axlsx</code> file in my <code>app/views/layouts</code> folder but rather the <code>mailer.text.erb</code> I am trying to use as with other emails.</p>
  
  <p>EDIT</p>
  
  <p>I changed the render line to <code>xlsx = render_to_string(template: 'v1/reports/azamara_social', params: {start_date: '2016-09-12', period: 'weekly'})</code></p>
  
  <p>And now it seems to try and render the <code>xlsx</code> view but of course gets <code>nil:NilClass</code> errors when the <code>xlsx</code> view tries to reference instance variables defined in the reports controller.</p>