This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit bcf370d689673031073ba2ac5588afe41cc315c9 | |
Author: Younes SERRAJ <[email protected]> | |
Date: Sun Apr 21 19:07:22 2019 +0200 | |
Allow ActiveStorage to generate variants of BMP images | |
diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md | |
index 54fc949172..d524ecf7d6 100644 | |
--- a/activestorage/CHANGELOG.md | |
+++ b/activestorage/CHANGELOG.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 78260d5663702f153f6bae64073f9659de366946 | |
Author: Younes SERRAJ <[email protected]> | |
Date: Wed Apr 17 19:25:46 2019 +0200 | |
Mention more ActiveStorage hooks in Active Support Instrumentation guide [ci skip] | |
Hooks added: | |
- `service_download_chunk.active_storage` | |
- `service_update_metadata.active_storage` | |
- `preview.active_storage` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Model | |
class Profile < ApplicationRecord | |
has_one_attached :avatar | |
accepts_nested_attributes_for :avatar_attachment, allow_destroy: true | |
end | |
# Controller | |
class ProfilesController < ApplicationController | |
before_action :set_profile, only: [:show, :edit, :update, :destroy] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some_profile.avatar.analyze |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some_profile.avatar.attached? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
params.require(:customer).permit(:some_attribute, contracts_attachments_attributes: [:id, :_destroy]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assuming a model defined like so: | |
class Post < ApplicationRecord | |
has_one_attached :image | |
end | |
# ...you can join against :image_attachment to select posts having attached images: | |
Post.joins(:image_attachment).where('published_at >= ?', Time.now) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel < ActiveRecord::Base | |
has_one_attached :image | |
validate :image_size | |
private | |
def image_size | |
errors.add :image, 'too big' if image.blob.byte_size > 4096 | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some_profile.avatar.attach(io: File.open('/path/to/file'), filename: 'avatar.png') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= image_tag(record.attachment.representation(resize: '500x500') %> |