How to show link on add record only on specific route?

I want to show a link to add income record only on pages with route incomes/income_id/edit? What is the right way to do it? In my add i show all incomes in incomes.handlebars and show view to create form on incomes/index.handlebars. In incomes/edit.handlebars i show the edit form. I can put in incomes/edit.handlebars div with this link but i think it’s a stupid method.


  {{#each income in controller}}
    <li>{{#linkTo "incomes.edit" income}} {{}} {{/linkTo}}</li>
  // Here i want to show link to add record if it's edit url now.


{{view EmberMoney.NewIncomeView}} ->
  @resource 'incomes', ->
    @route 'index'
    @route 'edit', { path: '/:income_id/edit' }

  @resource 'currencies', ->
    @route 'index'
    @route 'edit', { path: '/:currency_id/edit' }

EmberMoney.IncomesRoute = Ember.Route.extend
  model: ->

EmberMoney.IncomesEditRoute = Ember.Route.extend
  setupController: (controller, model) ->
    if model.get('transaction') == @get('store').get('defaultTransaction')
      transaction = @get('store').transaction()
      transaction.add model
    controller.set('content', model)

  deactivate: ->

    submit: (record) -> 'didUpdateRecord', =>
        @transitionTo 'index'

EmberMoney.IncomesIndexRoute = Ember.Route.extend
  model: ->
  setupController: (controller, model) ->
    controller.set('content', model)

    submit: ->

You could actually check if the curent path matches what you need and display the link only then

{{#if isEditing}}
  {{linkTo ...}}

and then the controller would have something like

EmberMoney.IncomesController = Ember.ArrayController.extend({
  needs: "application",

  isEditing: function() {
    return this.get("controllers.application.currentPath") === "incomes.edit";
1 Like