"smiled your answer"

This commit is contained in:
nilsding 2014-12-14 15:06:10 +01:00
parent c9b5947e6b
commit 154c360e15
4 changed files with 25 additions and 15 deletions

View File

@ -0,0 +1,2 @@
class Notifications::Smiled < Notification
end

View File

@ -3,4 +3,8 @@ class Smile < ActiveRecord::Base
belongs_to :answer
validates :user_id, presence: true
validates :answer_id, presence: true
def notification_type(*_args)
Notifications::Smiled
end
end

View File

@ -81,7 +81,8 @@ class User < ActiveRecord::Base
# smiles an answer
# @param answer [Answer] the answer to smile
def smile(answer)
Smile.create(user: self, answer: answer)
smile = Smile.create(user: self, answer: answer)
Notification.notify answer.user, smile unless answer.user == self
increment! :smiled_count
answer.increment! :smile_count
end

View File

@ -27,22 +27,25 @@
%h6.media-heading.notification--user
= user_screen_name notification.target.source
%p.notification--text
followed you!
followed you
= time_ago_in_words notification.target.created_at
ago
.notification--icon
%i.fa.fa-users
%li.list-group-item
.media
.pull-left
%img.notification--img
.media-body
%h6.media-heading.notification--user
username
%p.notification--text
smiled at
%a your answer
some time ago!
.notification--icon
%i.fa.fa-smile-o
- when "Smile"
.pull-left
%img.notification--img{src: gravatar_url(notification.target.user)}
.media-body
%h6.media-heading.notification--user
= user_screen_name notification.target.user
%p.notification--text
smiled at
%a{href: show_user_answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id)}
your answer
= time_ago_in_words notification.target.created_at
ago
.notification--icon
%i.fa.fa-smile-o
%li.list-group-item
.media
.pull-left