#136
User Notifications
6-3-2018
Summary
Using the Notifications Rails Engine, we are able to add notifications to our applications based on certain events. The engine provides the schema and necessary controls and associations to seamlessly integrate into your app.
7
rails
notifications
engine
13:08
Summary
Using the Notifications Rails Engine, we are able to add notifications to our applications based on certain events. The engine provides the schema and necessary controls and associations to seamlessly integrate into your app.
7
Resources
Notifications Gem - https://github.com/rails-engine/notifications
Source - https://github.com/driftingruby/136-user-notifications
Summary
Terminalrails g notifications:install
rails db:migrate
rails g notifications:controllers
rails g notifications:viewsGemfilegem 'notifications'layouts/application.html.erb<div class='container'> <ul class='navigation'> <% if user_signed_in? %> <li><%= link_to pluralize(Notification.unread_count(current_user), 'Notification'), notifications_path %></li> <li><%= link_to current_user.email, main_app.edit_user_registration_path %></li> <li><%= link_to 'Logout', main_app.destroy_user_session_path, method: :delete %></li> <% else %> <li><%= link_to 'Login', main_app.new_user_session_path %></li> <% end %> </ul> <%= yield %> </div>
models/comment.rbclass Comment < ApplicationRecord
belongs_to :post
belongs_to :user
after_commit :create_notifications, on: :create
private
def create_notifications
Notification.create do |notification|
notification.notify_type = 'post'
notification.actor = self.user
notification.user = self.post.user
notification.target = self
notification.second_target = self.post
end
end
endviews/notifications/_post.html.erb<div class=''> <%= link_to notification.actor.email, main_app.user_path(notification.actor) %> has commented in <%= link_to notification.second_target.content, main_app.user_post_path(notification.user, notification.second_target) %> </div> <div class=''> <%= notification.target.content %> </div>
db/routes.rb mount Notifications::Engine => "/notifications"
If its not too much to ask. Can you please make a similar video for activity_notification gem? Its almost identical to this one, but it may be more optimized. https://github.com/simukappu/activity_notification
Second vote for the activity_notification. It looks very slick and something I'm gonna add in to my project soon.