Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Controller Registration & Swapping View Engine #117

autumn8 opened this Issue Apr 5, 2012 · 8 comments


None yet
5 participants

autumn8 commented Apr 5, 2012

Hi. Couldn't find any other contact options, and I have some questions....

  1. How does one register a controller with the app? (without creating a resource) eg:

router.match(‘/stinky’).to({controller: ‘Poo’, action: ‘index’});

I looked at the default , '/' -> Main controller for reference, but that seems to have been automatically registered with the app. Also tried registering the controller using a geddy.controller.ControllerName = require..... based on the model registration example. No luck.

  1. How does one go about swapping out ejs and using jade as the templating engine instead?



mde commented Apr 5, 2012

  1. You can actually create a "bare" controller (i.e., one with no model) with "geddy controller" (like "geddy model" or "geddy app"). It will create the correctly named controller and routes for you:

    $ geddy controller zooby
    [ADDED] app/controllers/zoobies.js
    Bare zoobies route added to config/router.js
    Created view templates.
  2. The templating is designed to be pluggable, but we have only implemented EJS so far. If you'd be interested in building the Jade adapter, I'd love to work with you to get that done. :)

autumn8 commented Apr 10, 2012

  1. Aah. thank you. Is there a way to force the naming convention. ie. to maintain the singular name rather than the plural.
  2. I'd be happy to look at it, if you could point me in the right direction.

piksel commented Apr 11, 2012

yes, having file names like "auths.js" and "apis.js" itches :)


mde commented Apr 28, 2012

I'm taking a look at this now, but a workaround would be to create the routes and controller files yourselves -- the "main" controller created by default in the app-scaffold is a good example to look at.


mde commented Apr 29, 2012

After doing a bit of research, it looks like the Rails way to handle this might include:

  • Add an irregular-plural in the inflections -- there's currently not a Geddy way to do this, but this is probably something we should add.
  • Set a :path property when creating the resource-route -- you don't want this either, because the file name for the controller is still plural
  • Just manually mod the route, filename, and controller-name to be singular -- this is simple, and easy to do in Geddy.

For example: do "geddy resource zooby" -- this will pluralize to "zoobies." Do the following to make it all singular:

  1. Open config/router.js, change router.resource('zoobies'); to router.resource('zooby');
  2. Change app/controllers/zoobies.js to app/controllers/zooby.js
  3. Open app/controller/zooby.js, change all references to "Zoobies" to "Zooby"


autumn8 commented May 8, 2012

I had gone the route of creating a resource and renaming to singular, but it kept breaking when I did that, so I thought there might be some registry object that was being created behind the scenes when a new resource was added but I must simply have renamed something incorrectly along the way . Will take another look. Thanks for the follow up. Much appreciated.

@Techwraith Techwraith closed this May 9, 2012


johnnygreen commented May 12, 2012

@autumn8 just did this myself. it seems that the controller still looks for the location of the template in the plural location (app/views/zoobies/whatever.html.ejs) even though, as recommended by @mde, i've grep'd for every occurrence of the plural and changed it to the singular. I suppose the quick answer is to override the default provided when using this.respond({template: 'app/views/zooby/whatever'})


mde commented May 13, 2012

Oh, this was originally in the context of a bare controller -- one without a template. Yes, to make it work with a specific template, the best way to do it right now is to pass an override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment