1
0

events_controller.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. class EventsController < ApplicationController
  2. before_action :load_event, except: [:index, :show]
  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 do
  18. load_event
  19. rescue ActiveRecord::RecordNotFound
  20. return_to = params[:return] or raise
  21. redirect_to return_to, allow_other_host: false
  22. end
  23. format.json { render json: @event }
  24. end
  25. end
  26. def reemit
  27. @event.reemit!
  28. respond_to do |format|
  29. format.html { redirect_back event_path(@event), notice: 'Event re-emitted.' }
  30. end
  31. end
  32. def destroy
  33. @event.destroy
  34. respond_to do |format|
  35. format.html { redirect_back events_path, notice: 'Event deleted.' }
  36. format.json { head :no_content }
  37. end
  38. end
  39. private
  40. def load_event
  41. @event = current_user.events.find(params[:id])
  42. end
  43. end