Sha256: e4a7e931d24ab66f5ab8492e61721066425bc7d0b01910872aaa7016cc487de9

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

class Manage::BallotBox::VotesController < Manage::BaseController
  inherit_resources
  
  actions :index, :show, :destroy
  defaults :route_prefix => 'manage', :resource_class => BallotBox::Vote, 
           :collection_name => 'votes', :instance_name => 'vote'  
  
  respond_to :json, :only => [:show]
  
  before_filter :find_voteable
  before_filter :make_filter, :only=>[:index]
  
  authorize_resource :class => BallotBox::Vote
  
  helper_method :voteable_scope
    
  def destroy
    destroy!{ manage_ballot_box_votes_path( voteable_scope(@voteable) ) }
  end
  
  def show
    respond_with(@voteable) do |format|
      format.json { render :json => @voteable.votes.chart(params[:id]) }
    end
  end
  
  protected
    
    def begin_of_association_chain
      @voteable
    end
    
    def collection
      @votes = (@votes || end_of_association_chain).page(params[:page]).merge(@search.scoped)
    end
    
    def find_voteable
      klass = params[:voteable_type].to_s.classify.constantize
      @voteable = klass.find(params[:voteable_id])
    end
    
    def make_filter
      @search = Sunrise::ModelFilter.new(BallotBox::Vote, :attributes => [ :voter_type, :voter_id, :ip_address, 
                    :browser_name, :browser_version, :browser_platform])
      @search.update_attributes(params[:search])
    end
    
    def voteable_scope(record)
      { :voteable_id => record.id, :voteable_type => record.class.name }
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sunrise-votes-0.1.1 app/controllers/manage/ballot_box/votes_controller.rb