Class: CountersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/counters_controller.rb

Overview

A stupid little controller showing how easy you can build generic “counter” functionality when they’re represented as a model

Instance Method Summary collapse

Instance Method Details

#destroyObject

Reset a counter to 0



5
6
7
8
9
# File 'app/controllers/counters_controller.rb', line 5

def destroy
  Counter::Value.find(params[:id]).reset!

  redirect_back fallback_location: "/"
end

#updateObject

Recalculate a counter



12
13
14
15
16
# File 'app/controllers/counters_controller.rb', line 12

def update
  Counter::Value.find(params[:id]).recalc!

  redirect_back fallback_location: "/"
end