Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Mountable notifications for any Rails applications.
$ bundle add notifications
You now have a notifications generator in your Rails application:
$ rails g notifications:install
You can generate views, controllers if you need to customize them:
$ rails g notifications:views
$ rails g notifications:controllers
class User
def follow(user)
Notification.create(notify_type: 'follow', actor: self, user: user)
end
end
class Comment
belongs_to :post
belongs_to :user
after_commit :create_notifications, on: [:create]
def create_notifications
Notification.create(
notify_type: 'comment',
actor: self.user,
user: self.post.user,
target: self)
end
end
Get unread notifications count for a user:
# unread count
unread_count = Notification.unread_count(current_user)
# read count
read_count = Notification.read_count(current_user)
# for non-user class
Notifications.config.user_class = 'Member'
#or change
Notifications.configure do
# Class name of you User model, default: 'User'
self.user_class = 'User'
# Method of user name in User model, default: 'name'
# self.user_name_method = 'name'
# Method of user avatar in User model, default: nil
# self.user_avatar_url_method = nil
# Method name of user profile page path, in User model, default: nil
# self.user_profile_url_method = 'profile_url'
# authenticate_user method in your Controller, default: nil
# If you use Devise, authenticate_user! is correct
# self.authenticate_user_method = 'authenticate_user!'
# current_user method name in your Controller, default: 'current_user'
# If you use Devise, current_user is correct
# self.current_user_method = 'current_user'
end
If you create a notify_type, you need to add a partial view in app/views/notifications/
path, for example:
# There have two notify_type
Notification.create(notify_type: 'follow' ....)
Notification.create(notify_type: 'mention', target: @reply, second_target: @topic, ....)
Your app must have:
# app/views/notifications/_follow.html.erb
<div class="media-heading">
<%= link_to notification.actor.title, main_app.user_path(notification.actor) %> just followed you.
</div>
# app/views/notifications/_mention.html.erb
<div class="media-heading">
<%= link_to notification.actor.title, main_app.user_path(notification.actor) %> has mentioned you in
<%= link_to notification.second_target.title, main_app.topic_path(notification.second_target) %>
</div>
<div class="media-content">
<%= notification.target.body %>
</div>
NOTE: When you want use Rails route path name in notification views, you must use main_app prefix. etc:
main_app.user_path(user)
It is recommended that you use second_level_cache for solving N+1 performance issues.
Testing for multiple Rails versions:
make test_51
# or test all
make test
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that notifications demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.