How do I register a public asset in a plugin?

Forgive me if this has been asked before, but I am unable to find a previous topic on this.

I’m wondering how to register an asset as public (such as an image) through a discourse plugin - it seems currently after registering, I get a 404 or 302 response when installing under a private member’s only site.

This is in reference to the Discord oauth plugin I built - I am unable to retrieve the image either directly, or through a register_asset call.

How would I go about serving static plugin assets in this case?

3 个赞

你好,我也可以获取信息吗?因为我遇到了同样的问题。

当然可以,那个主题帖已被删除。该主题帖提供了一个旧版 Discourse 插件的链接,其中包含如何在插件中注册公共资产的示例:https://github.com/eviltrout/trout_emoji。

根据我最后的测试,将图片添加到插件的 public/images 目录后,这些图片将在服务器上通过 /plugins/插件名称/images/ 路径可用。

路径中使用的插件名称是你在 plugin.rb 文件顶部的元数据中指定的插件名称,例如 /plugins/trout_emoji/images/trout-square.jpg

6 个赞

非常感谢。现在它已经正常工作了。问题是因为我以为路径中的插件名称就是文件夹名称 :slight_smile:

1 个赞