1
0

events_controller.rb 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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: @event }
  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. redirect_to :back, :notice => "Event re-emitted"
  24. end
  25. def destroy
  26. @event.destroy
  27. respond_to do |format|
  28. format.html { redirect_to events_path }
  29. format.json { head :no_content }
  30. end
  31. end
  32. private
  33. def load_event
  34. @event = current_user.events.find(params[:id])
  35. end
  36. end