LoginSignup
8
6

More than 3 years have passed since last update.

Rails6 Action Text アップロードされた画像のファイル名と画像サイズを非表示にする方法

Last updated at Posted at 2020-03-18

こんにちは、「おすし」です。

最近ぶろぐを始めようと思い、 Action Txet を Rails6 で使おうと思い、導入までは順調だったのですが、いざ画像をアップロードすると、、、

スクリーンショット 2020-03-18 18.33.49.png

なんとアップロードした画像の下にデフォルトでファイル名と画像サイズが表示されています!!!!

解決方法は....Action Textを導入した時に自動的に作成されたこのファイルから...↓

views/activestorage/blobs/_blob.html.erb

<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 ]) %>
    <% 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>

figcaptionタグ含め、ネストされているコードを全て消します。


views/activestorage/blobs/_blob.html.erb

<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 ]) %>
   <% end %>
</figure>

これだけ!

見てくださりありがとうございます。
それでは、お体ご自愛ください。

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6