app/controllers/manage/ballot_box/votes_controller.rb in sunrise-votes-0.1.0 vs app/controllers/manage/ballot_box/votes_controller.rb in sunrise-votes-0.1.1
- old
+ new
@@ -1,36 +1,51 @@
class Manage::BallotBox::VotesController < Manage::BaseController
inherit_resources
- belongs_to :idea, :polymorphic => true
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]
- load_and_authorize_resource :idea, :through => :challenge
+ authorize_resource :class => BallotBox::Vote
+
+ helper_method :voteable_scope
def destroy
- destroy!{ manage_ballot_box_votes_path(:"#{parent_type}_id" => parent.id) }
+ destroy!{ manage_ballot_box_votes_path( voteable_scope(@voteable) ) }
end
def show
- respond_with(parent) do |format|
- format.json { render :json => parent.votes.chart(params[:id]) }
+ 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