사용자가 버튼을 클릭 할 때 관리자에게 경고를 보낼 수 있기를 바랍니다. 일종의 "도와 줘", 메시지. 나는 보았고 current_user.admin으로 if else 문을 수행한다는 것을 알고 있습니까? 하지만 여기서 어디로 가야할지 모르겠습니다.
매우 기본적인 구현은 모델을 호출 HelpTicket
하고 사용자가 도움말 버튼을 눌렀을 때 데이터베이스에 새 티켓을 생성하는 것과 같습니다.
그런 다음 새 티켓이있을 때마다 관리자에게 이메일을 보내거나 응답하지 않은 티켓이있는 경우 관리자가 로그인 할 때마다 확인하고 알릴 수 있습니다.
# create_help_tickets_table_migration.rb
create_table :help_tickets do |t|
t.integer :user_id
t.text :description
t.integer :status, default: 0
t.timestamps null: false
end
# help_ticket.rb
class HelpTicket < ActiveRecord::Base
belongs_to :user
enum :status, [:unanswered, :completed]
end
# help_tickets_controller.rb
class HelpTicketsController < ApplicationController
def create
ticket = HelpTicket.new(params.permit(:description))
ticket.user_id = current_user
render :ok if ticket.save
end
end
# application_controller.rb
class ApplicationController
before_action :check_help_tickets, if: Proc.new { current_user.admin? }
def check_help_tickets
flash[:notice] = "There are unattended help tickets" if HelpTicket.unanswered.exists?
end
end
이것이 당신에게 방향, 행운을 빕니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다