module Formol
  class PollVotesController < ApplicationController
    include Controllers::Nested::HasParentTopic
    
    def create
      formol_authorize!(current_formol_user, :vote_poll, topic)
      
      poll.vote(current_formol_user, params['poll']['poll_vote_ids'])
    rescue Formol::Poll::PollException => e
      flash[:error] = t(e.message)
    ensure
      respond_to do |format|
        format.html { redirect_to [topic.forum, topic] }
      end
    end
    
    protected
    
    def poll
      @poll ||= topic.poll
    end
  end
end
