title: RoR-STimulus-Fetch-API : how to add something fetched to DB
body: <p>I am trying to add something I fetched from an API to my RoR DB.</p>
  <p>So I have :</p>
  <ul>
  <li><p>my view :</p>
  <pre><code>&lt;div data-controller=&quot;album&quot;&gt;
  
    &lt;form data-album-target = &quot;form&quot;
       data-action=&quot;submit-&gt;album#update&quot;&gt;
    &lt;input  type=&quot;text&quot;
          class=&quot;form-control&quot;
          data-album-target=&quot;input&quot;&gt;
  
    &lt;div data-album-target=&quot;results&quot;&gt;&lt;/div&gt;
  
    &lt;/div&gt;
  </code></pre>
     
  </li>
  <li><p>and my stimulus controller</p>
  <pre><code>  import { Controller } from &quot;stimulus&quot;
  
       export default class extends Controller {
      static targets = [&quot;results&quot;, &quot;input&quot;, &quot;form&quot;]
  
  update(event) {
    event.preventDefault();
    this.resultsTarget.innerHTML = &quot;&quot;;
    const artistName = this.inputTarget.value;
    const url = `https://theaudiodb.com/api/v1/json/2/search.php?s=${artistName}`;
    fetch(url)
      .then(response =&gt; response.json())
      .then((data) =&gt; {
        this.findIdArtist(data);
      });
  }
  
  findIdArtist(data){
    data.artists.forEach((result) =&gt; {
      const idArtist = result.idArtist;
      const url2 = `https://theaudiodb.com/api/v1/json/2/album.php?i=${idArtist}`;
      fetch(url2)
        .then(response =&gt; response.json())
        .then((data) =&gt; {
          data.album.sort(function (a, b) { return a.intYearReleased - b.intYearReleased }).forEach((list) =&gt; {
            const album =
              `&lt;div class=&quot;card&quot;&gt;
                &lt;img src=${list.strAlbumThumb}&gt;
                &lt;div class=&quot;albumtitle&quot;&gt;
                  ${list.strAlbum}
                &lt;/div&gt;
                &lt;div class=&quot;albumyear&quot;&gt;
                  ${list.intYearReleased}
                &lt;/div&gt;
              &lt;/div&gt;`
            this.resultsTarget.insertAdjacentHTML(&quot;beforeend&quot;, album)
          })
        });
    });
  }
  }
  </code></pre>
  </li>
  </ul>
  <p>How could I have a &quot;+&quot; button which adds the albumID to my RoR database ? I tried with a POST fetch but I can't get it to work.</p>
  <p>Any idea ?</p>
  <p>Thanks !</p>