Class VotersController
In: app/controllers/voters_controller.rb
Parent: ApplicationController

Methods

add   list   set  

Public Instance methods

POST /voters/add

Return

Added voter.

Post

XML of voter to add.

[Source]

    # File app/controllers/voters_controller.rb, line 9
 9:   def add
10:     return unless request.post?
11:     xml = LibXML::XML::Parser.parse(request.raw_post)
12:     @voters = xml.find("/voters/voter").inject([]) do |voters, voter|
13:       cur_voter = Voter.create(:user_id => current_user.id)
14:       voter.find("features/feature").each do |feature|
15:         Feature.create(:voter_id => cur_voter.id, :name => feature.attributes["name"], :value => feature.content.to_i)
16:       end
17:       voters << cur_voter
18:     end
19:   end

GET /voters/list

Return

List of user‘s voters.

[Source]

    # File app/controllers/voters_controller.rb, line 24
24:   def list
25:     @voters = Voter.all(:conditions => { :user_id => current_user.id }, :include => :features)
26:   end

GET /voters/set/1

Return

Voter.

Options (params)

id<String>:Converted to integer. Id of voter to set. Must belong to user.
{}<Hash>:Name, value pairs of features to set. Any non spaces or

alphanumerics plus _ are removed from name.

Raises

PermissionError:If voter does not belong to user.

[Source]

    # File app/controllers/voters_controller.rb, line 37
37:   def set
38:     p = params.clone
39:     @voter = Voter.find(p.delete(:id).to_i, :conditions => { :user_id => current_user.id }, :include => :features)
40:     raise PermissionError unless @voter
41:     p.delete(:action)
42:     p.delete(:controller)
43:     p.delete(:format)
44:     p.each do |name, value|
45:       # only space, alphanumerics, or _
46:       name = name.gsub(/[^(' '|\w)]/, '')
47:       feature = Feature.first(:conditions => { :voter_id => @voter.id, :name => name })
48:       if feature
49:         feature.update_attribute(:value, value.to_i)
50:       else
51:         feature = Feature.new(:name => name, :value => value.to_i)
52:         @voter.features << feature
53:       end
54:     end
55:   end

[Validate]