1

I have a nested edit route for one of my resources:

@resource 'organization', path: 'organizations/:organization_id', ->
  @resource 'organization.edit', path: '/edit'

I link to it like this (using Emblem.js):

linkTo 'organization.edit' organization | Edit

Unfortunately, this results in a url like:

/organizations/4#

Rather than the expected:

/organizations/4/edit

Any idea why this is happening? I experimented with the route syntax a lot. Removing path for organization.edit does nothing, as does a full path: 'organization/:organization_id/edit.

nullnullnull
  • 8,039
  • 12
  • 55
  • 107

3 Answers3

1

You should be able to get your desired result by using this type of nesting structure:

App.Router.map(function() {
  this.resource("organizations", function(){
    this.resource("organization", { path: "/:organization_id" }, function(){
      this.route("edit");
    });
  });
});

JSBin example

CraigTeegarden
  • 8,173
  • 8
  • 38
  • 43
  • 1
    Your JSBin does the trick. Actually, I don't even have to nest the outer-most `organizations`. My mistake was using the syntax `linkTo 'organization.edit' organization` rather than `linkTo 'organization.edit' this`. Reading through your JSBin code revealed my error. Thanks for typing that out! – nullnullnull Oct 10 '13 at 18:53
0

You're on the right track but @resource is really intended for objects, e.g. organizations. If you're defining an action (not nested resources) you'll want to use @route, i.e.:

@resource 'organization', path: 'organizations/:organization_id', ->
  @route 'edit'

I believe that should give you the expected behaviour / routing.

gorner
  • 552
  • 2
  • 8
  • Thanks for the quick reply! Unfortunately, the problem persists with this setup. If you have any other ideas, please send them my way. – nullnullnull Oct 10 '13 at 17:04
0

Why not use something like this:

@resource 'organization', ->
  @route "edit",
    path: "/:organization_id/edit"
Max Popoff
  • 111
  • 1
  • 5