Martin Vrkljan
Martin Vrkljan

Reputation: 879

Is it possible to change sails.js blueprint-generated camel case controller route?

I'm testing out Sails.js and trying to connect to Ember.js on the frontend, but am running into problems with automatically generated controller method routes in Sails.

I have a TestModel model generated in Sails.js and I can query the model via http://localhost:1337/testModel, or even better for connectivity with Ember, I can set the pluralize blueprint config option to true to have that be http://localhost:1337/testModels.

However, Ember's naming convention produces requests like http://localhost:1337/test-models for the data store query methods.

Is there any way to automatize Sails.js to generate spinal-case instead of camelCase? Or if not, is it possible to have Ember do it?

I'm trying to find a solution that doesn't include writing custom config for every problematic model name.

Upvotes: 2

Views: 896

Answers (2)

Jason Sims
Jason Sims

Reputation: 1158

In sails v0.10 you can specify a custom API resource identity by overriding the identity property on both the model and the controller.

// FooResourceController.js
module.exports = {
  identity: 'foo_resource'
}

// FooResource.js
module.exports = {
  identity: 'foo_resource',
  attributes: {

  }
}

// Routes bound on lift
//
// get    /foo_resource
// post   /foo_resource
// put    /foo_resource
// delete /foo_resource

Upvotes: 2

Kingpin2k
Kingpin2k

Reputation: 47367

You can remedy this really easy in Ember data by querying for testModels instead of test-models

App.IndexRoute = Ember.Route.extend({
  model: function() {
    return this.get('store').find('testColor');
  }
});

http://emberjs.jsbin.com/OxIDiVU/164/edit

Upvotes: 3

Related Questions