# 是否有办法获得已发布的帖子，但又不显示 onebox？

**URL:** <https://meta.discourse.org/t/is-there-a-route-to-get-a-cooked-post-but-without-rendered-oneboxes/167157>\
**Category:** Product Support\
**Created:** [2020 年10 月 14 日 08:10 UTC](https://meta.discourse.org/t/is-there-a-route-to-get-a-cooked-post-but-without-rendered-oneboxes/167157 "2020-10-14T08:10:07Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

作者： ![neounix](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neounix/32/215617_2.png) [@neounix](https://meta.discourse.org/u/neounix)\
发布日期： [2020 年10 月 21 日 12:16 UTC](https://meta.discourse.org/t/is-there-a-route-to-get-a-cooked-post-but-without-rendered-oneboxes/167157/13 "2020-10-21T12:16:47Z")

</div>

> [@Terrapop](#):
>
> 如果能直接从 Discourse 获取解析后的 HTML 就好了，只是不要那些 oneboxes。

只需隐藏或移除该 DOM 元素即可。这其实很简单。

1. 将用户代理字符串与 Ruby 进行匹配，并在匹配时设置一个布尔值。
2. 如果该布尔值为真，则使用 JavaScript 隐藏该 DOM 元素。

这基本上就是“标准”做法，适用于开发者不希望显示（或想要移除）任何 DOM 元素的类似场景。

* * *

**注意：**

使用 Ruby 的 ‘gon’ gem 可以非常轻松地将任何 Ruby 变量传递给 JavaScript，不过我仅在 Rails 应用中使用过它，尚未在包含 EmberJS 的栈中使用（无论如何，将 Ruby 变量传递给 JS 的方法有很多）。

---

_[View the full topic](https://meta.discourse.org/t/is-there-a-route-to-get-a-cooked-post-but-without-rendered-oneboxes/167157)._
