Skip to content

Instantly share code, notes, and snippets.

@bhserna
Created October 23, 2013 22:20
Show Gist options
  • Save bhserna/7127803 to your computer and use it in GitHub Desktop.
Save bhserna/7127803 to your computer and use it in GitHub Desktop.
emberjs vs frontend hacks --- emberjs
{{#if currentUser.questionsToAnswer}}
<span class="navbar-menu__badge">
{{currentUser.questionsToAnswerCount}}
</span>
{{/if}}
App.QuestionController = Ember.ObjectController.extend
createAnswer: ->
body = @get 'newAnswerBody'
return if !body.trim()
question = @get 'model'
answer = App.Answer.createRecord question: question, body: body
@set 'newAnswerBody', ''
@get('store').commit()
App.User = DS.Model.extend
questions: DS.hasMany("App.Question")
questionsToAnswer: (->
@get('questions').filterProperty('hasAnswer', false)
).property('[email protected]')
questionsToAnswerCount: (->
@get("questionsToAnswer").get('length')
).property('questionsToAnswer')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment