# Comment lier des images avec un sujet

**URL:** <https://meta.discourse.org/t/how-to-link-images-with-topic/321246>\
**Category:** Development\
**Created:** [Août 12, 2024, 12:38 UTC](https://meta.discourse.org/t/how-to-link-images-with-topic/321246 "2024-08-12T12:38:13Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [Août 13, 2024, 10:58 UTC](https://meta.discourse.org/t/how-to-link-images-with-topic/321246/5 "2024-08-13T10:58:56Z")

</div>

Voici le code qui met à jour le sujet `image_upload_id`, il se trouve dans `CookedPostProcessor::update_post_image`

> <https://github.com/discourse/discourse/blob/355dbb928a2b9e8319fa4c0bba38876559ae0a5d/lib/cooked_post_processor.rb#L322-L329>

Vous pourriez donc faire un [monkey patch de cette fonction](https://medium.com/@sebastianroyer/prepend-and-super-for-elegant-monkey-patching-24a5b98f4468) et ensuite faire quelque chose comme

```rb
def update_post_image
  super # appel à l'original
  if @post.custom_fields[:your_field_name_upload_id]
    upload_id = @post.custom_fields[:your_field_name_upload_id]
    @post.update_column(:image_upload_id, upload_id) # post
    if @post.is_first_post? # sujet
        @post.topic.update_column(:image_upload_id, upload_id)
    end
  end
end

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-link-images-with-topic/321246)._
