プラグインでボタンを押した後にテキストボックスのデータを取得する

初めてのプラグインを開発しており、ボタンを押した後に管理パネル(プラグインの一部)のテキストボックスの内容を取得したいと考えています。その後、Rubyでその内容を使って何か処理を行いたいのですが、EmberのフロントエンドからRubyのバックエンドにデータを送信する方法はありますか?
私の plugin.rb

# name: Discourse Sample Plugin
# about: A simple plugin to play around with
# version: 1.0.0
# authors: NateDhaliwal
# url: https://google.com

enabled_site_setting :plugin_enabled

add_admin_route 'sample_page.title', 'sample-page'

Discourse::Application.routes.append do
  get '/admin/plugins/sample-page' => 'admin/plugins#index', constraints: StaffConstraint.new
end

私の assets/javascripts/discourse/templates/admin/plugin-sample-plugin.hbs

<div class="textbox">
  <input id="textbox-data" type="text" />
</div>

<div class="buttons">
  <DButton
    @label="sample_page.send"
    @action={{action "sendTextboxData"}}
    @icon="arrow-right"
    @id="send-textbox-data"
  />
</div>

sendTextboxData が何をすべきか分かりません。
私の assets/javascripts/discourse/sample-page-route-map.js

export default {
  resource: 'admin.adminPlugins',
  path: '/plugins',
  map() {
    this.route('sample-page');
  }
};

私の assets/javascripts/discourse/controllers/admin-plugins-sample-plugin.js.es6

import Controller from "@ember/controller";
import { action } from "@ember/object";

export default class AdminPluginsSamplePlugin extends Controller {

  @action
  sendTextboxData() {
    // データを送信するにはどうすればよいですか?
  }
}

もしデータをRubyのバックエンドに送信できたら、データ処理のロジックはどこに記述すればよいですか? plugin.rb ですか? それとも別のファイルですか?

それとも設定の方がより理想的でしょうか?しかし、私のユースケースでは、テキストボックスは毎回値を保持する必要がありません。YMLはこの機能を提供しますか?Rubyでサイト設定を変更できますか?

RubyでJSから呼び出せるAPIを作成したいようですね。例えば、Data Explorerプラグインは、Ruby側で管理者権限スコープを持つユーザー入力APIを実装しています。

Data ExplorerのJSはかなり複雑なので、おそらく必要となるであろう簡単な例を示します。

import { ajax } from "discourse/lib/ajax";

...
  @action
  sendTextboxData() {
    ajax("/endpoint", {
        type: "POST",
        data: {
          key: "value"
        },
    }).then((result) => {
        // 結果を使って何かをする
    };
  }

ネイティブJSのfetch()でも同じことができますが、Discourseが提供するajax()関数は、内部でいくつかの細かい処理を処理してくれるようです。

Rubyコードが十分に軽量であれば、コントローラー全体を1つのファイルに収めることができるでしょう。そうでなければ、必要に応じて整理してください。

「いいね!」 2