Amrit
Amrit

Reputation: 2072

What is the ember way to handle non-resource functions?

Get-Post-Put-Delete requests for resources are fine. I want to know what is the ember way to handle non-resource functions?

For example, I have a button to vote a user up/down, and it has a route like /vote/up/2343 and /vote/down/2343 - it also binds the current displayed users vote counts.

Or we have a button, which should display a modal form, and once submitted to backend, an email should be sent.

Thanks!

Upvotes: 0

Views: 45

Answers (1)

Michael Benin
Michael Benin

Reputation: 4332

Not sure if I'm totally understanding the question but my interpretation is that you want actions not a route.

For that specific route/resource there is a controller. In that controller you have an actions property.

actions:{
  voteUp: function(){
    this.incrementProperty('votes');
    // Make ajax request to server 
    this.get('content').save(); // whatever implementation on your model
  }
}

In your template you indicate what element responds to the action.

<button {{action 'voteUp'}}>Vote Up</button>

In your controller where you have your defined actions, you can also have methods that can make ajax requests and change your model properties, in this case votes.

For your modal dialog, I suggest reading up on the EmberJS Documentation: http://emberjs.com/guides/cookbook/user_interface_and_interaction/using_modal_dialogs/

Upvotes: 1

Related Questions