How to add Cloudinary files as email attachments in Action Mailer Ruby
Hi,
I'm using rails 6.0.3.4 and need to send emails automatically at the updating of my ArtistsMetric instance that
has_many_attached :justification_files
Here is my code in the ApplicationMailer:
def artists_metric_verification_files
@artists_metric = params[:artists_metric]
mail(to:(to: "dontspam@me.com", subject: "<%= @artists_metric.artist.name %> infos updated at <%= @artists_metric.updated_at %> ")
And in artists_metric_verification_files.html.erb:
<%= @artists_metric.artist.name %>
<%= cl_image_tag(@artists_metric.justification_files.each { |file| file, flags: "attachment"}) %>
My error is:
Encountered a syntax error while rendering template: check <%= @artists_metric.artist.name %> <%= cl_image_tag(@artists_metric.justification_files.each { |file| file, flags: "attachment"}) %>
By the way, I have tried to use the ancient syntax, but it doesn't work neither(same syntax error but with the "=>":
<%= cl_image_tag(@artists_metric.justification_files.each { |file| file, :flags => "attachment"}) %>
Would you please help me? I'm pretty sure it is a very simple change but I can't find the answer...
-
Can you loop artist_metrics outside of the cl_image_tag? Maybe something across these lines:
<% @artists_metric.justification_files.each do |file| %>
cl_image_tag(file, flags:attachment)
<% end %>0 -
I am also facing same issue and don't know what to do.
0 -
Hi @Jonny0000,
Did you have a chance to try the suggestion by Daniel above - what was the result?
0 -
Did anyone tried Daniel suggestion.
0 -
Hi @singh,
If you're running into this issue also please give Daniel's suggestion a try and let me know how it goes.
0 -
Some else tried his suggestions.
-1 -
Hi @Resi,
I'm not sure I understand what you mean - could you please provide more details/context about your response?
0 -
Hi @Resi,
I have tried to follow the instructions provided above but I didn't succeed. I think the post doesn't contain full details of information that I need.
0 -
Hi @MichaelWik,
In order to get a better understanding of the implementation that you would like to achieve, can you please help to open a support ticket here (https://support.cloudinary.com/hc/en-us/requests/new) and provide us the sample source code showing the errors you are encountering (e.g., through Github or Replit would be helpful)?
Thanks.
0
Post is closed for comments.
Comments
9 comments