В настоящее время у меня есть система уведомлений, когда пациенты заполняют форму, которую они просят подписать у врача. Врач успешно уведомлен. Но я ищу, когда врач получает уведомление, что он может щелкнуть по нему (link_to) и автоматически перенаправится на форму.
<% if @notifications.count > 0 %>
<ul>
<% @notifications.each do |notification| %>
<li>
<span class = "notification-title"><%= notification.title %></span>
<span class = "notification-message"><%= notification.message %></span>
<span class = "notification-time"><%= notification.created_at.strftime("%B %e at %l:%m%P") %></span>
</li>
<% end %>
</ul>
<div class = "notifications-preview-footer">
<%= link_to "See All", notifications_path %>
</div>
<% else %>
<ul>
<li>No Notifications</li>
</ul>
<% end %>





Я изменил диапазон заголовков с помощью образца link_to, поэтому, если заголовок щелкнул, он перейдет на страницу показа уведомлений
<% if @notifications.count > 0 %>
<ul>
<% @notifications.each do |notification| %>
<li>
<%= link_to <span class = "notification-title"><%= notification.title %></span>, notification_path(notification) %>
<span class = "notification-message"><%= notification.message %></span>
<span class = "notification-time"><%= notification.created_at.strftime("%B %e at %l:%m%P") %></span>
</li>
<% end %>
</ul>
<div class = "notifications-preview-footer">
<%= link_to "See All", notifications_path %>
</div>
<% else %>
<ul>
<li>No Notifications</li>
</ul>
<% end %>
Здесь много неизвестного, сначала вы должны указать маршруты в файле routes.rb, чтобы это можно было сказать
# config/routes.rb
resources: notifications
Затем вам нужно определить действия контроллера для представления, возможно, показать / отредактировать?
# notifications_controller.rb
class NotificationsController < ApplicationController
def show
@notification = Notification.find(params[:id])
end
end
Затем вы можете изменить вид, как указано выше, чтобы разрешить ссылку на каждое уведомление.
<% @notifications.each do |notification| %>
<li>
<%= link_to <span class = "notification-title"><%= notification.title %></span>, notification_path(notification) %>
<span class = "notification-message"><%= notification.message %></span>
<span class = "notification-time"><%= notification.created_at.strftime("%B %e at %l:%m%P") %></span>
</li>
<% end %>
Это может дать вам то, что вы ищете.