1
0

events_controller.rb 980 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class EventsController < ApplicationController
  2. before_action :load_event, except: :index
  3. def index
  4. if params[:agent_id]
  5. @agent = current_user.agents.find(params[:agent_id])
  6. @events = @agent.events.page(params[:page])
  7. else
  8. @events = current_user.events.preload(:agent).page(params[:page])
  9. end
  10. respond_to do |format|
  11. format.html
  12. format.json { render json: @events }
  13. end
  14. end
  15. def show
  16. respond_to do |format|
  17. format.html
  18. format.json { render json: @event }
  19. end
  20. end
  21. def reemit
  22. @event.reemit!
  23. respond_to do |format|
  24. format.html { redirect_back event_path(@event), notice: 'Event re-emitted.' }
  25. end
  26. end
  27. def destroy
  28. @event.destroy
  29. respond_to do |format|
  30. format.html { redirect_back events_path, notice: 'Event deleted.' }
  31. format.json { head :no_content }
  32. end
  33. end
  34. private
  35. def load_event
  36. @event = current_user.events.find(params[:id])
  37. end
  38. end