Code Monkey home page Code Monkey logo

Comments (10)

samuelshih avatar samuelshih commented on June 29, 2024 3

@straydogstudio I figured it out!!

xlsx = (render_to_string handlers: [:axlsx], formats: [:xlsx],
    template: "report", layout: false)
attachments["#{subject}.xlsx"] = { mime_type: Mime::XLSX, content: xlsx }
  mail(
      to: [email protected],
      from: "[email protected]",
      subject: subject,
      template_path: 'mailer',
      template_name: "report"
    )

The template in the xlsx block report can't have the same name as the html template. So I had to rename it to

xlsx = (render_to_string handlers: [:axlsx], formats: [:xlsx],
    template: "xls_report", layout: false)
attachments["#{subject}.xlsx"] = { mime_type: Mime::XLSX, content: xlsx }

It was always breaking on mail( ....), so I was thinking it might be getting the template names confused even when I wasn't attaching the xlsx file, so there it is 😄

from caxlsx_rails.

samuelshih avatar samuelshih commented on June 29, 2024

@straydogstudio any updates?

from caxlsx_rails.

straydogstudio avatar straydogstudio commented on June 29, 2024

Sorry @samuelshih I haven't been able to get to it. One way you could help is to create a simple Rails repo in Github that demonstrates the issue. Then I won't have to set that up, and it will make sure I have the setup you do (with the entire Gemfile.) Would you be willing to do that?

from caxlsx_rails.

straydogstudio avatar straydogstudio commented on June 29, 2024

Fantastic! That's great. I think I may know what that means then, but I'll have to check on that. Nice to have a simple solution!

from caxlsx_rails.

straydogstudio avatar straydogstudio commented on June 29, 2024

I'm going to leave this open as a reminder to look into this.

from caxlsx_rails.

kikihakiem avatar kikihakiem commented on June 29, 2024

Hey @straydogstudio , I also faced the same problem. It looks like rails are trying to surround the xlsx file with layouts:
screen shot 2015-11-29 at 4 55 20 pm

To fix this problem I have to either rename the axlsx template or by passing render layout: false, so my controller action looks like this:

respond_to do |format|
  format.html
  format.xlsx { render layout: false } # avoid surrounding xml with layout
end

I prefer the later one.

from caxlsx_rails.

straydogstudio avatar straydogstudio commented on June 29, 2024

@kikihakiem Thanks for the update. The format.xls really shouldn't come into play, as I don't register anything under that MIME type. But that is interesting.

What Rails / Axlsx / axlsx_rails versions do you have?

from caxlsx_rails.

kikihakiem avatar kikihakiem commented on June 29, 2024

Rails 4.2.4, axlsx 2.0.1, axlsx_rails 0.4.0
I'm using stdlib for format.xls. However I got the same issue when generating xls file and the solution is also same, so I think it's rails issue.

from caxlsx_rails.

straydogstudio avatar straydogstudio commented on June 29, 2024

I have not been able to reproduce this bug. But, based on the experience of others (here and in other issues) the latest release of axlsx_rails (0.5.0) explicitly sets layout to false. Advising others to set the layout to false appears to fix these issues. I am cautiously optimistic. Please try 0.5.0 and comment on this issue (or open another) if the failure happens again.

from caxlsx_rails.

nachokb avatar nachokb commented on June 29, 2024

ref #29 (dupe)

from caxlsx_rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.