如何从注意到的宝石中创建动态参数
我正在使用注意到GEM进行通知,并试图以更清洁的方式使用户获得与帖子和对话相关的通知。该通知将帖子存储为参数中的对象。我遇到了很多重复的代码,因为我的小组中有对话中的对话,并与其中的帖子进行了讨论。因此,我有一个“ post_notification”和一个“对话_notification”。因此,当用户检查他的通知时,这是现在对我有用的。
- if notification.params[:conversation]
- if avatar_url_for(notification.to_notification.params[:conversation].user).present?
= image_tag avatar_url_for(notification.to_notification.params[:conversation].user, size: 35), class: "rounded-circle"
- else
= image_tag "no-photo-avatar.png", class: "rounded-circle"
- if notification.params[:post]
- if avatar_url_for(notification.to_notification.params[:post].user).present?
= image_tag avatar_url_for(notification.to_notification.params[:post].user, size: 35), class: "rounded-circle"
- else
= image_tag "no-photo-avatar.png", class: "rounded-circle"
- noticed_notification = notification.to_notification
= link_to noticed_notification.message, noticed_notification.url
by:
- if notification.params[:conversation]
= notification.params[:conversation].user.full_name
- if notification.params[:post]
= notification.params[:post].user.full_name
如何使它更好地不重复或动态?我想创建一种方法,以使其更清洁而不重复,以便我可以在Navbar Nevbar Notification下拉和通知页面上使用它
I am using Noticed gem for my notifications and I am trying to get the users for the notifications related to the post and conversation in a cleaner way. The notification stores the post as an object inside params. I'm running into a lot of repeating code because I have Groups with conversations in it and Discussions with posts in it. So I have a "post_notification" and a "conversation_notification". So when a user checks his notifications this is what's working for me right now.
- if notification.params[:conversation]
- if avatar_url_for(notification.to_notification.params[:conversation].user).present?
= image_tag avatar_url_for(notification.to_notification.params[:conversation].user, size: 35), class: "rounded-circle"
- else
= image_tag "no-photo-avatar.png", class: "rounded-circle"
- if notification.params[:post]
- if avatar_url_for(notification.to_notification.params[:post].user).present?
= image_tag avatar_url_for(notification.to_notification.params[:post].user, size: 35), class: "rounded-circle"
- else
= image_tag "no-photo-avatar.png", class: "rounded-circle"
- noticed_notification = notification.to_notification
= link_to noticed_notification.message, noticed_notification.url
by:
- if notification.params[:conversation]
= notification.params[:conversation].user.full_name
- if notification.params[:post]
= notification.params[:post].user.full_name
How can I make this better not repeating or dynamic? I wanted to create a method where it's cleaner and not repeating so I can use it on the navbar notification dropdown and notification page
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论