mdarby (owner)

Revisions

gist: 161408 Download_button fork
public
Public Clone URL: git://gist.github.com/161408.git
Embed All Files: show embed
Ruby #
1
2
3
4
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class PollsController < ApplicationController
  resource_controller
  actions :all, :except => [:show]
 
 
  create.wants.html { redirect_to collection_url }
  update.wants.html { redirect_to collection_url }
  destroy.wants.html { redirect_to collection_url }
 
 
  def vote
    unless object.has_already_voted?(current_user)
      object.votes.create!(:user => current_user, :vote => params[:poll]["vote"])
    end
 
    redirect_to collection_url
  end
 
 
  private
 
    def collection
      @collection ||= Poll.visible
    end
 
end
 
 
# class PollsController < ApplicationController
#
# before_filter :load_items
#
# def load_items
# object = Poll.find(params[:id]) if params[:id]
# end
#
# def index
# objects = Poll.visible
# end
#
# def show
# redirect_to polls_path
# end
#
# def new
# object = Poll.new
# end
#
# def edit
# end
#
# def create
# object = Poll.new(params[:poll])
#
# if object.save
# flash[:notice] = "Poll successfully created"
# redirect_to polls_path
# else
# render :action => "new"
# end
# end
#
# def update
# if object.update_attributes(params[:poll])
# flash[:notice] = 'Poll was successfully updated.'
# redirect_to polls_path
# else
# flash[:error] = "An error occurred"
# render :action => "edit"
# end
# end
#
# def destroy
# object.destroy
# redirect_to polls_path
# end
#
# def vote
# unless object.has_already_voted?(current_user)
# v = object.votes.build(:user => current_user, :vote => params[:poll]["vote"])
#
# if v.save
# flash[:notice] = "Vote cast!"
# else
# flash[:error] = "Something happened..."
# end
# end
#
# redirect_to polls_path
# end
#
# end