# テーマコンポーネントでDBからデータを取得するにはどうすればよいですか？

**URL:** <https://meta.discourse.org/t/how-do-you-pull-in-data-from-the-db-for-your-theme-components/143995>\
**Category:** Development\
**Created:** [2020 年 3 月 12 日午前 5:00 UTC](https://meta.discourse.org/t/how-do-you-pull-in-data-from-the-db-for-your-theme-components/143995 "2020-03-12T05:00:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![justin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/justin/32/157614_2.png) [@justin](https://meta.discourse.org/u/justin)\
**Post date:** [2020 年 3 月 12 日午前 11:38 UTC](https://meta.discourse.org/t/how-do-you-pull-in-data-from-the-db-for-your-theme-components/143995/2 "2020-03-12T11:38:46Z")

</div>

これにはいくつかの方法があります。最も簡単な方法は、表示したいデータを提供する Rails API のエンドポイントに対して Ajax 呼び出しを行うことです。最新の 20 件のトピックを取得したい場合は、`/latest.json` を試してみてください。

課題は、複数のエンドポイントから情報を組み合わせる必要がある場合、複数の呼び出しが完了するのを待つ必要があり、それがテーマコンポーネントのパフォーマンスを大幅に低下させる可能性があることです。

---

_[View the full topic](https://meta.discourse.org/t/how-do-you-pull-in-data-from-the-db-for-your-theme-components/143995)._
