Class: BcmsPolling::PollingController

Inherits:
ApplicationController
  • Object
show all
Includes:
PollsHelper, Cms::Authentication::Controller
Defined in:
app/controllers/bcms_polling/polling_controller.rb

Instance Method Summary collapse

Methods included from PollsHelper

#cookie_for, #response_results

Instance Method Details

#resetObject



32
33
34
35
36
37
38
39
# File 'app/controllers/bcms_polling/polling_controller.rb', line 32

def reset
  @poll           = Poll.find(params[:id])

  cookie          = cookie_key(@poll)
  cookies.delete(cookie)

  redirect_to "/"
end

#resultsObject



27
28
29
30
# File 'app/controllers/bcms_polling/polling_controller.rb', line 27

def results
  @poll = Poll.find(params[:id])
  render :layout => false
end

#updateObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/bcms_polling/polling_controller.rb', line 7

def update
  @response  = PollResponse.find(params[:id])
  unique_key = cookie_key(@response.poll)

  if !cookies[unique_key]
    @response.votes += 1
    @response.save!

    cookies[unique_key] = {
        :value   => true,
        :expires => 1.year.from_now
    }
    logger.warn "Saving cookie called '#{unique_key}'"
  else
    logger.warn "User attempted to submit another answer to the same poll."
  end

  render :nothing => true, :status => :ok
end