Reputation: 1680
I have a Book
model instance and would like to get a href
string to it given its route. Eg:
someEmberJSMethod('book.edit', aBookInstance) #=> "/books/12/edit"
Given the route:
@resource "books", ->
@route "edit", path: "/:book_id/edit"
I tried looking at the Ember.js source and how link-to
helper generates the href
given the route name and the instance, but didn't manage to find the answer.
Upvotes: 0
Views: 493
Reputation: 1680
While this doesn't answer the question, some might find it useful. A way of getting a simple show
url to an object from the controller would be the following:
adapter = this.store.adapterFor('application')
adapter.buildURL('book', @get('id')) // => '/books/12
Upvotes: 0
Reputation: 6397
You can generate routes the same way the link view does by accessing the router:
App.Router.router.generate('book.edit', aBookInstance) # => '/books/12/edit'
You didn’t give the context of your application or where this request is happening. If you’re using Ember CLI and this is within a controller, for instance, you’ll have to look up the router with something like this:
@get('container').lookup('router:main')
Upvotes: 1