Skip to content

Instantly share code, notes, and snippets.

@yshmarov
Created May 14, 2021 10:15
Show Gist options
  • Save yshmarov/f4515ebf631d3cc6f1720b0a91dbc7e7 to your computer and use it in GitHub Desktop.
Save yshmarov/f4515ebf631d3cc6f1720b0a91dbc7e7 to your computer and use it in GitHub Desktop.
blob active_Storage
app/views/active_storage/blobs/_blob.html.haml
<%= render "active_storage/blobs/blob", blob: @post.avatar %>
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
<% if blob.representable? %>
<%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
<% elsif blob.image? %>
<%= image_tag blob, width: "200px" %>
<% elsif blob.audio? %>
<audio controls>
<source src="<%= rails_blob_url(blob) %>" type="<%= blob.content_type %>"></source>
</audio>
<% elsif blob.video? %>
<video controls width="480">
<source src="<%= rails_blob_url(blob) %>" type="<%= blob.content_type %>"></source>
</video>
<% end %>
<figcaption class="attachment__caption">
<% if caption = blob.try(:caption) %>
<%= caption %>
<% else %>
<span class="attachment__name"><%= blob.filename %></span>
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
<% end %>
</figcaption>
</figure>
@yshmarov
Copy link
Author

yshmarov commented May 15, 2021

Action Mailer

class UserMailer < ApplicationMailer

def user_created
    @greeting = Post.count
    @user = params[:user]
    @post = params[:post]
    attachments.inline['favicon2.png'] = File.read('app/assets/images/favicon2.png')
    mail(
	to: email_address_with_name(User.first.email, User.first.email), 
	cc: User.all.pluck(:email),
	bcc: "secret@secret.com", 
	subject: "new post created!"
	)
    end
end
<%= image_tag attachments['favicon2.png'].url, width: 100, alt: 'Corsego' %>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment