# Plugin Development: record.save() returns 404

**URL:** https://meta.discourse.org/t/plugin-development-record-save-returns-404/88998
**Category:** Support
**Created:** [June 2, 2018, 2:12pm UTC](https://meta.discourse.org/t/plugin-development-record-save-returns-404/88998 "2018-06-02T14:12:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [June 2, 2018, 2:12pm UTC](https://meta.discourse.org/t/plugin-development-record-save-returns-404/88998/1 "2018-06-02T14:12:45Z")

</div>

I’m trying to develop a plugin and save records to the store (as described in [Upgrading our front end models to use a store](https://meta.discourse.org/t/upgrading-our-front-end-models-to-use-a-store/27837)). I can create the record successfully, call `save()`, but it will only return a 404 at `/routes`.

**`./plugins/plugin-name/assets/javascripts/discourse/controllers/admin-plugins-plugin-name.js.es6`** :

```plaintext
const routeRecord = this.store.createRecord('route', { propA, propB });
routeRecord.save()
  .then(result => {
    console.log(result);
  }
  .catch(error => {
    console.error(error);
  }
  .finally(() => {
    console.log('Done');
  }

```

I seem to be missing some sort of model for the type of record I want to store. Without the model below, the POST request to `routes` isn’t sent out. Implementing the model on my own, the request is sent, but returns a 404. I don’t know what is necessary for it to work properly. It looks like this:

**`./plugins/plugin-name/assets/javascripts/discourse/models/route.js.es6`** :

```plaintext
import RestModel from 'discourse/models/rest';

export default RestModel.extend({
  _init: function() {
    this._super();
  }.on('init'),

  createProperties() {
    return {
      propA: this.getProperties('propA'),
      propB: this.getProperties('propB')
    };
  }
});

```

What is required for `/routes` to be a valid end point?

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [June 4, 2018, 6:18pm UTC](https://meta.discourse.org/t/plugin-development-record-save-returns-404/88998/3 "2018-06-04T18:18:17Z")

</div>

By default, when you call save on your model, it’ll make a `POST` to `/<recordname>`.

I tried your example code and it seems that `route` is a reserved name, so I would recommend you use a different name.

Did you implement a server side route for your record to save to? For example a type of `widget` would save to `/widgets` as a `POST`. You can run `rake routes` on the command line to see the routes you’ve created.

---

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [June 5, 2018, 2:18pm UTC](https://meta.discourse.org/t/plugin-development-record-save-returns-404/88998/4 "2018-06-05T14:18:42Z")

</div>

In the meantime, I learned a couple of things. I neither have a background in any kind of back end programming nor do I know Ruby/Rails/Ember. That’s why when writing my observations, there wasn’t any server-side controller answering the requests. I managed to implement working data transfer between the client and the server as I need it.

I am able to use **`routes`** as an endpoint (i.e. I’m doing `this.store.createRecord('route', ...)` and requests are being sent to `/routes`, `/routes/:route_id`, etc.). Though from what you say, it sounds logical to use a different name for the endpoint, right?

Maybe I should write a tutorial on implementing basic data exchange using _the store_ (is there a better name for that?) for transferring data between client and server and _PluginStore_ for transferring data between application and persistent storage. That might be helpful for a few people.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [June 6, 2018, 3:11pm UTC](https://meta.discourse.org/t/plugin-development-record-save-returns-404/88998/5 "2018-06-06T15:11:12Z")

</div>

> [@kleinfreund](#):
>
> I am able to use **`routes`** as an endpoint (i.e. I’m doing `this.store.createRecord('route', ...)` and requests are being sent to `/routes` , `/routes/:route_id` , etc.). Though from what you say, it sounds logical to use a different name for the endpoint, right?

Your code is likely working because you defined a new `route` class, but that is a conflict with Ember’s route and setting yourself up for weird errors in the future. I highly recommend you use a different name for your model/endpoint.

> [@kleinfreund](#):
>
> Maybe I should write a tutorial on implementing basic data exchange using _the store_ (is there a better name for that?) for transferring data between client and server and _PluginStore_ for transferring data between application and persistent storage. That might be helpful for a few people.

Sure, more documentation is always great!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [July 19, 2018, 2:45pm UTC](https://meta.discourse.org/t/plugin-development-record-save-returns-404/88998/6 "2018-07-19T14:45:26Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
