You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to export data to excel and send it to client who wants.
But there is problem in my setup, I am getting MissingTemplate error.
controller/posts_controller.rb
# GET /posts
def index
@posts = Post.all
PostMailer.export(@posts, current_user).deliver
render json: @posts
end
views/posts/export.xlsx.axlsx
wb = xlsx_package.workbook
wb.add_worksheet(name: "Posts") do |sheet|
posts.each do |post|
sheet.add_row [post.title, post.content, post.creator.name]
end
end
mailers/post_mailer.rb
class PostMailer < ApplicationMailer
def export(posts, user)
xlsx = render_to_string layout: false, handlers: [:axlsx], formats: [:xlsx], template: "posts/export", locals: {posts: posts}
attachment = Base64.encode64(xlsx)
attachments["Posts.xlsx"] = {mime_type: Mime[:xlsx], content: attachment, encoding: "base64"}
mail(to: user.email, subject: "Posts") do |f|
f.text do
render text: nil
end
end
end
end
What am I doing wrong?
Thanks.
The text was updated successfully, but these errors were encountered:
Whatever is producing that error is an environment specific issue in combination with Rails 5 and the url called. Each time someone has reported that error, I've never been able to reproduce it with similar conditions. Hence my request for a sample repo.
Hi,
I want to export data to excel and send it to client who wants.
But there is problem in my setup, I am getting MissingTemplate error.
controller/posts_controller.rb
views/posts/export.xlsx.axlsx
mailers/post_mailer.rb
What am I doing wrong?
Thanks.
The text was updated successfully, but these errors were encountered: