-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mailer attachement #12
Comments
Stupidly enough, I've never tried it. I may have to make some changes. I'll test it within a few days. In the meantime, you can use the axlsx gem directly inside the mailer, rendering a pdf. That, however, removes the advantage of a template. Or, abstract that into some class method you use both in the template and the mailer. |
ok, thanks For the moment, I create the file with a controller and I write myself the mail. |
how can i help you to implement/test/... this new fonctionnality ? |
I should get to it this week. But there is one thing you can do: Try it with an abs path that is only two deep. E.g. |
for all test, with an abs path only two deep (with an without changing the location of the view) , I have this error:
if i use the standart form of rendering (path 2 or 3 deep) I hope that this information will help you. I am always available to do other tests. |
Thanks. I'll use this and let you know if I can use any more testing. |
@gagalago Ok I think I have this figured out. It isn't really a bug. However, you can use def export
xlsx = render_to_string handlers: [:xlsx], template: "/administration/contracts/social_secretariat"
attachments["Nouvelles entrées.xlsx"] = {mime_type: Mime::XLSX, content: xlsx}
...
end Let me know if that works for you. If it does I'll close the issue. Note that you don't have to specify I've added tests and will be updating the docs sometime today or tomorrow. Thanks for submitting the issue. |
With your instruction, I have this error : |
What rails are you using? I'm still fixing the tests for Rails 4. |
@gagalago Send me your whole mailer code if you can. I'm not finding any way to reproduce your error. |
@gagalago You might try something like: def export
ac = ActionController::Base.new()
xlsx = ac.render_to_string handlers: [:xlsx], template: "/administration/contracts/social_secretariat"
attachments["Nouvelles entrées.xlsx"] = {mime_type: Mime::XLSX, content: xlsx}
...
end |
I use rails 3.2.11 and my mailer code: # coding: utf-8
class SocialSecretariatMailer < ActionMailer::Base
default :from => "Didier Leser - CESAM Nature <didier.leser@cesam-nature.com>"
def export
to=["info@cesam-nature.com", ""]
content_type = "multipart/alternative"
attachments["Nouvelles entrées.xlsx"] = {mime_type: Mime::XLSX, content: new_entries_file}
subject="xlsx: CESAM Nature"
mail(:to=>to,:subject=>subject) do |format|
format.text { render :text => "xlsx CESAM Nature" }
end
end
private
def new_entries_file
save_xlsx(Employee.not_deleted.confirmed, "employés nouvelles entrées")
end
def save_xlsx(employees, title)
if employees.size>0
@employees = employees
ac = ActionController::Base.new()
xlsx = ac.render_to_string handlers: [:xlsx], template: "/administration/employees/social_secretariat"
xlsx
end
end
end with this new syntax, I have this error:
If i use a mix of controller and your mailer syntax: ac = ActionController::Base.new()
xlsx = ac.render_to_string :xlsx => "/administration/contracts/social_secretariat"
attachments["Nouvelles entrées.xlsx"] = {mime_type: Mime::XLSX, content: xlsx} I get an error that says that a helper function is unknown
I hope that this new information will help us to solve these problems. ps: I'm still here tomorrow and then I leave for two weeks holiday |
Ugh. After all this, I think I sent you a typo at the first. I hope this is it, (and I'll be embarrassed too.) Try this: def export
to=["info@cesam-nature.com", ""]
content_type = "multipart/alternative"
xlsx = render handlers: [:axlsx], template: "/administration/contracts/social_secretariat"
attachments["Nouvelles entrées.xlsx"] = {mime_type: Mime::XLSX, content: xlsx}
subject="xlsx: CESAM Nature"
mail(:to=>to,:subject=>subject) do |format|
format.text { render :text => "xlsx CESAM Nature" }
end
end Notice I still don't understand why render_to_string isn't available for you, and all my web searching has not been fruitful on that point. |
Using av = ActionView::Base.new()
av.view_paths = ActionController::Base.view_paths
av.extend ApplicationHelper #Here you would include the id_for_social_secretariat helper
av.assign employees: employees
xlsx = av.render handlers: [:axlsx], template: "/administration/contracts/social_secretariat" Note in one of your posts you use |
@gagalago: I haven't heard from you in a while. Do you have any more information? Is it working for you? |
thanks. All works ! And my code : # coding: utf-8
class SocialSecretariatMailer < ActionMailer::Base
default :from => "Thibault Poncelet - CESAM Nature <thibault.poncelet@cesam-nature.com>"
def export
#to=["info@cesam-nature.com", "gagalago@gmail.com"]
to = ["gagalago@gmail.com"]
content_type = "multipart/alternative"
attachments["Nouvelles entrées.xlsx"] = {mime_type: Mime::XLSX, content: new_entries_file}
subject="xlsx: CESAM Nature"
mail(:to=>to,:subject=>subject) do |format|
format.text { render :text => "xlsx CESAM Nature" }
end
end
private
def new_entries_file
save_xlsx(Employee.not_deleted.confirmed.new_export, "employés nouvelles entrées")
end
def save_xlsx(employees, title)
if employees.size>0
av = ActionView::Base.new()
av.view_paths = ActionController::Base.view_paths
av.extend SocialSecretariatHelper
av.assign employees: employees
av.render handlers: [:axlsx], template: "/administration/employees/social_secretariat"
end
end
end Don't forget to update your documentation ;-) sorry for answering so late and thank you again. |
When I use this method I get the content of the file inline in email. |
@chrisgogreen Create a new issue, and post your mailer code in it. |
In case someone else is still having this problem with the syntax provided in the README, I got my template working using the following lines in the mailer:
The template file is named report.xlsx.axlsx |
@mejiaro Just to be clear, you dropped the handlers specifier? Which version of Rails, Axlsx, axlsx_rails? |
Yup, just removed the handlers. rails (4.2.5.1), axlsx (2.0.1), axlsx_rails (0.4.0) |
@mejiaro Thanks. I will update the docs at least. |
How can i use axls_rails within a mailer to have a attachement ?
in the mailer :
the error
I feel that it is an error from the default rendered and not from the axls renderer.
Is it impossible to achieve this or I've made a mistake ?
The text was updated successfully, but these errors were encountered: