# Acessando outro modelo no Ember — certamente há uma maneira melhor que ajax

**URL:** <https://meta.discourse.org/t/accessing-another-model-in-ember-surely-theres-a-better-way-than-ajax/216695>\
**Category:** Development\
**Created:** [Fevereiro 1, 2022, 2:23pm UTC](https://meta.discourse.org/t/accessing-another-model-in-ember-surely-theres-a-better-way-than-ajax/216695 "2022-02-01T14:23:03Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [Fevereiro 1, 2022, 2:23pm UTC](https://meta.discourse.org/t/accessing-another-model-in-ember-surely-theres-a-better-way-than-ajax/216695/1 "2022-02-01T14:23:03Z")

</div>

Estou inserindo um botão no cabeçalho que adiciona um usuário a um grupo. Isso está funcionando, mas fazer uma chamada `ajax` para isso não parece certo. Pareceria que eu poderia “apenas” chamar o modelo `Group` e fazer isso lá, mas não consigo encontrar um exemplo que faça isso.

Isso está em um plugin…

Acho que deve haver alguma maneira de transformar `demoGroup` em um modelo em vez de apenas um `dict`?

```plaintext
      const demoServerGroupName = siteSettings.pfaffmanager_demo_server_group;
      const groups = Site.currentProp("groups");
      const router = container.lookup("router:main");

      const demoGroup = groups.find((g) => {
        return g.name === demoServerGroupName;
      });
      const hasDemoServer = servers.find((g) => {
        return g.hostname.includes("pfaffmanagerdemo");
      });
      if (demoGroup && !hasDemoServer) {
        api.decorateWidget("header-buttons:before", (helper) => {
          const addToDemoGroup = function () {
            window.console.log("precisa adicionar ao grupo", demoGroup);

            const groupId = demoGroup.id;
            const url = `/groups/${groupId}/join.json`;
            ajax(url, {
              type: "PUT",
              data: currentUser.username,
            })
              .then(() => {
                router.transitionTo("/pfaffmanager/servers"); //TODO: refer to the route?
              })
              .catch(popupAjaxError);
          };

          return helper.h(
            "button#newDemoServer",
            {
              className: "btn btn-text btn-primary create headerLink",
              title: I18n.t("pfaffmanager.server.create_demo_server_title"),
              onclick: addToDemoGroup,
            },
            I18n.t("pfaffmanager.server.create_demo_server_short")
          );
        });
      }

```

---

_[View the full topic](https://meta.discourse.org/t/accessing-another-model-in-ember-surely-theres-a-better-way-than-ajax/216695)._
