Class: PollResponseController

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

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/poll_response_controller.rb', line 5

def create
  @page = Page.find(params[:page_id])
  @page.request, @page.response = request, response

  poll = Poll.find(params[:poll_id])
  current_poll = Poll.find_current
  
  # Use cookies instead of sessions, to limit multiple responses on same poll
  # assign the submitted polls from cookies to the current page so we can
  # pass it off to our radius tags
  @page. = @page.poll_cookies(cookies)

  if !@page..include?(poll.id) && (!current_poll || current_poll.id == poll.id)

    begin
      poll_cookie_duration = eval(config['polls.cookie_duration']).from_now || 1.month.from_now
    rescue Exception => exc
      poll_cookie_duration = 1.month.from_now
    end

    cookies["poll_#{poll.id.to_s}"] = { :value => "#{@page.id}", :expires => poll_cookie_duration }
    @page. << poll.id

    poll_response = Option.find(params[:response_id])
    poll.submit_response(poll_response)
  end    

  redirect_to @page.url
end