text1
text1
text1

how to link image?

64 views Asked by At

I use Active Storage and Active Text. When I paste text and pictures in text_area, it create html like this:

    <div class="trix-content">
      <div>text1<action-text-attachment sgid="eyJfcmFp..." content-type="image/jpeg" url="http://localhost:3000/rails/active_storage/blobs/redirect/...index2.jpeg" filename="index2.jpeg" filesize="12622" width="275" height="183" previewable="true" presentation="gallery"><figure class="attachment attachment--preview attachment--jpeg">
        <img src="http://localhost:3000/rails/active_storage/representations/redirect/eyJfc.../index2.jpeg">
    
      <figcaption class="attachment__caption">
          <span class="attachment__name">index2.jpeg</span>
          <span class="attachment__size">12.3 KB</span>
      </figcaption>
    </figure></action-text-attachment>text2<action-text-attachment sgid="eyJfcmFp..." content-type="image/jpeg" url="http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcm.../index1.jpeg" filename="index1.jpeg" filesize="12528" width="275" height="183" previewable="true" presentation="gallery"><figure class="attachment attachment--preview attachment--jpeg">
        <img src="http://localhost:3000/rails/active_storage/representations/redirect/eyJfcmFpbHM.../index1.jpeg">
    
      <figcaption class="attachment__caption">
          <span class="attachment__name">index1.jpeg</span>
          <span class="attachment__size">12.2 KB</span>
      </figcaption>
    </figure></action-text-attachment>text3<action-text-attachment sgid="eyJfcm..." content-type="image/jpeg" url="http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcm.../index.jpeg" filename="index.jpeg" filesize="11570" width="259" height="194" previewable="true" presentation="gallery"><figure class="attachment attachment--preview attachment--jpeg">
        <img src="http://localhost:3000/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBMZz09IiwiZX.jpeg">
    
      <figcaption class="attachment__caption">
          <span class="attachment__name">index.jpeg</span>
          <span class="attachment__size">11.3 KB</span>
      </figcaption>
    </figure></action-text-attachment>
    </div>
    </div>

Rails adds images and text to news.body. I need to show image like link on index page. Proly I need to wrap image to link_to but I don't know how and where it make. This is _news.html.erb(I know name for model(new) is bad choice):

    <p class="italic">
      <%= news.title %>
    </p>
    <p class="font-bold">  
      <%= news.body %>
    </p>
    
    <%= button_to 'Delete', news_path(news), data:{ turbo: false }, method: :delete %>
    <%= link_to 'Show', news_path(news), data:{ turbo: false } %> 
    <hr/>

How and where to wrap link_to image for index.html.erb?

0

There are 0 answers