2014-03-23 00:22:25 +00:00
|
|
|
class PollsController < ApplicationController
|
2020-03-16 23:57:47 +00:00
|
|
|
before_action :get_poll, except: [:index, :new, :create]
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@polls = Poll.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@poll = Poll.new
|
|
|
|
@poll.options.build
|
|
|
|
raise AccessError unless @poll.can_create? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
raise AccessError unless @poll.can_update? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-03-18 03:38:17 +00:00
|
|
|
@poll = Poll.new(Poll.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
@poll.user = cuser
|
|
|
|
raise AccessError unless @poll.can_create? cuser
|
|
|
|
|
|
|
|
if @poll.save
|
|
|
|
flash[:notice] = t(:polls_create)
|
|
|
|
redirect_to @poll
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :new
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
raise AccessError unless @poll.can_update? cuser
|
|
|
|
|
2020-03-18 03:38:17 +00:00
|
|
|
if @poll.update_attributes(Poll.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
flash[:notice] = t(:polls_update)
|
|
|
|
redirect_to @poll
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :edit
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
raise AccessError unless @poll.can_destroy? cuser
|
|
|
|
@poll.destroy
|
|
|
|
redirect_to polls_url
|
|
|
|
end
|
|
|
|
|
2017-03-23 23:07:39 +00:00
|
|
|
def showvotes
|
|
|
|
raise AccessError unless cuser.admin?
|
|
|
|
end
|
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def get_poll
|
|
|
|
@poll = Poll.find params[:id]
|
|
|
|
end
|
|
|
|
end
|