Class: ErrorTrack::ErrorsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ErrorTrack::ErrorsController
- Defined in:
- app/controllers/error_track/errors_controller.rb
Constant Summary collapse
- SESSION_AVAILABLE =
CSRF protection (and the CSRF token/meta tags themselves) only work when a session store is actually in the middleware stack. API-only Rails apps strip out ActionDispatch::Session/Flash/Cookies by default, and touching the session without it raises. So we detect this once and skip CSRF entirely when there's no session backing it - this lets the same controller work in a full Rails app and an
--apiapp with zero configuration. begin Rails.application.middleware.any? { |m| m.klass.name.to_s.include?("Session") } rescue false end
Instance Method Summary collapse
-
#destroy ⇒ Object
DELETE /errors/:id.
-
#index ⇒ Object
GET /errors (HTML shell) GET /errors.json (JSON list).
-
#reopen ⇒ Object
POST /errors/:id/reopen.
-
#resolve ⇒ Object
POST /errors/:id/resolve.
-
#show ⇒ Object
GET /errors/:id.json.
Instance Method Details
#destroy ⇒ Object
DELETE /errors/:id
81 82 83 84 85 |
# File 'app/controllers/error_track/errors_controller.rb', line 81 def destroy event = ErrorTrack::ErrorEvent.find(params[:id]) event.destroy head :no_content end |
#index ⇒ Object
GET /errors (HTML shell) GET /errors.json (JSON list)
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/error_track/errors_controller.rb', line 27 def index scope = ErrorTrack::ErrorEvent.recent scope = case params[:filter] when "resolved" then scope.resolved when "all" then scope else scope.unresolved end page = [params[:page].to_i, 1].max per_page = 25 total = scope.count events = scope.offset((page - 1) * per_page).limit(per_page) respond_to do |format| format.html { render "error_track/errors/index" } format.json do render json: { errors: events.map { |e| serialize_event(e) }, meta: { page: page, per_page: per_page, total: total, total_pages: (total.to_f / per_page).ceil } } end end end |
#reopen ⇒ Object
POST /errors/:id/reopen
74 75 76 77 78 |
# File 'app/controllers/error_track/errors_controller.rb', line 74 def reopen event = ErrorTrack::ErrorEvent.find(params[:id]) event.reopen! render json: serialize_event(event) end |
#resolve ⇒ Object
POST /errors/:id/resolve
67 68 69 70 71 |
# File 'app/controllers/error_track/errors_controller.rb', line 67 def resolve event = ErrorTrack::ErrorEvent.find(params[:id]) event.resolve! render json: serialize_event(event) end |
#show ⇒ Object
GET /errors/:id.json
57 58 59 60 61 62 63 64 |
# File 'app/controllers/error_track/errors_controller.rb', line 57 def show event = ErrorTrack::ErrorEvent.find(params[:id]) occurrences = event.occurrences.recent.limit(20) render json: serialize_event(event).merge( occurrences: occurrences.map { |o| serialize_occurrence(o) } ) end |