How to use the rails-ujs.csrfToken function in rails-ujs

To help you get started, we’ve selected a few rails-ujs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github connorshea / vglist / app / javascript / src / components / game-in-library.vue View on Github external
onDelete() {
      if (
        window.confirm(
          `Remove ${this.gameInLibrary.game.name} from your library?`
        )
      ) {
        // Post a delete request to the game purchase endpoint to delete the game.
        fetch(this.gameInLibrary.url, {
          method: 'DELETE',
          headers: {
            'X-CSRF-Token': Rails.csrfToken(),
            Accept: 'application/json'
          },
          credentials: 'same-origin'
        }).then(response => {
          if (response.ok) {
            // Emit a delete event to force the parent library component to
            // refresh.
            this.$emit('delete');
          }
        });
      }
    }
  },
github connorshea / vglist / app / javascript / src / components / release-form.vue View on Github external
let platform_id = this.release.platform.id;
      let developer_ids = Array.from(this.release.developers, developer => developer.id);
      let publisher_ids = Array.from(this.release.publishers, publisher => publisher.id);
      fetch(this.submitPath, {
        method: this.create ? 'POST' : 'PUT',
        body: JSON.stringify({ release: {
          name: this.release.name,
          description: this.release.description,
          game_id: game_id,
          platform_id: platform_id,
          developer_ids: developer_ids,
          publisher_ids: publisher_ids
        }}),
        headers: {
          'Content-Type': 'application/json',
          'X-CSRF-Token': Rails.csrfToken()
        },
        credentials: 'same-origin'
      }).then(function(response) {
        if (!response.ok) {
          throw Error(response.statusText);
        }
        return response;
      }).then(function(data) {
        Turbolinks.visit(data.url);
      }).catch(function(error) {
        console.log(error);
      });
    }
  }

rails-ujs

Ruby on Rails unobtrusive scripting adapter

MIT
Latest version published 2 years ago

Package Health Score

78 / 100
Full package analysis

Similar packages