Post cook for images?


(fearlessfrog) #1

I have a very simple plugin (server-side) I was playing around with.

For this part of the call:

on(:post_created) do |post, params|

I use the post.raw to put some content in:

post.raw = "@#{post.user.username} says hello!\n\n"
post.save

…and it works great. Cool.

My question is how to embed an image, as in the same result as when the post cooks in the preview editor?

If I change it to something like this:

post.raw = "https://discourse-meta.s3-us-west-1.amazonaws.com/optimized/3X/9/d/9d543e92b15b06924249654667a81441a55867eb_1_690x184.png\n\n"
post.save

…then the post shows the plain image address text and not the preview image. If I open edit on the post manually in the UI it works ok (shows the image preview), just not on my post save.

Looking through the code, am I meant to call ‘post.cook’ after the save to trigger this?

Thanks for any help or pointers to examples.


(fearlessfrog) #2

I solved this by putting the image into an IMG tag within the raw format, i.e.

post.raw = "<img src='https://discourse-meta.s3-us-west-1.amazonaws.com/optimized/3X/9/d/9d543e92b15b06924249654667a81441a55867eb_1_690x184.png'/>\n\n"

post.save

…means that it cooks on the save fine now.