Class PeopleController
In: app/controllers/people_controller.rb
Parent: ApplicationController

Methods

account   card   create_login   index   list   new_login   show   update  

Included Modules

Api::People

Public Instance methods

[Source]

    # File app/controllers/people_controller.rb, line 48
48:   def account
49:     person = (params[:id] && Person.find(params[:id])) || current_person
50:     if person
51:       redirect_to edit_person_path(person)
52:     else
53:       session[:return_to] = "/account"
54:       redirect_to new_person_session_url(secure_redirect_options)
55:     end
56:   end

Print membership card

[Source]

    # File app/controllers/people_controller.rb, line 68
68:   def card
69:     respond_to do |format|
70:       format.pdf do
71:         send_data Card.new.to_pdf(@person), 
72:                   :filename => "card.pdf", 
73:                   :type => "application/pdf"
74:       end
75:     end
76:   end

[Source]

     # File app/controllers/people_controller.rb, line 89
 89:   def create_login
 90:     @return_to = params[:return_to]
 91:     
 92:     if params[:person][:license].present? && params[:person][:name].blank?
 93:       @person = Person.new(params[:person])
 94:       @person.errors.add :name, "can't be blank if license is present"
 95:       return render(:new_login)
 96:     end
 97:     
 98:     if params[:person][:license].present?
 99:       @person = Person.find_all_by_name_like(params[:person][:name]).detect { |person|
100:         person.license == params[:person][:license].strip
101:       }
102: 
103:       if @person && @person.login.present?
104:         flash.now[:warn] = "Sorry, there's already a login for license ##{params[:person][:license]}. <a href=\"/password_resets/new\" class=\"obvious\">Forgot your password?</a>"
105:         return render(:new_login)
106:       end
107:       
108:       if @person.nil?
109:         @person = Person.new
110:         @person.errors.add_to_base "Didn't match your name and license number. Please check your #{RacingAssociation.current.short_name} membership card."
111:       end
112:     end
113:     @person = Person.new if @person.nil?
114:     @person.attributes = params[:person]
115:     
116:     if params[:person][:password].blank?
117:       @person.errors.add :password, "can't be blank"
118:     end
119:     
120:     if params[:person][:email].blank?
121:       @person.errors.add :email, "can't be blank"
122:     end
123:     
124:     if params[:person][:email].blank? || !params[:person][:email][Authlogic::Regex.email]
125:       @person.errors.add :email, "must been email address"
126:     end
127:     
128:     if params[:person][:login].blank?
129:       @person.errors.add :login, "can't be blank"
130:     end
131:     
132:     if params[:person][:license].present? && params[:person][:license].strip[/\D+/]
133:       @person.errors.add :license, "should only be numbers"
134:     end
135:     
136:     if params[:person][:name].present? && params[:person][:name].strip[/^\d+$/]
137:       @person.errors.add :name, "is a number. Did you accidently type your license in the name field?"
138:     end
139: 
140:     if @person.errors.any?
141:       return render(:new_login)
142:     end
143:     
144:     if @person.update_attributes(params[:person])
145:       flash[:notice] = "Created your new login"
146:       PersonMailer.deliver_new_login_confirmation(@person) rescue nil
147:       if @return_to.present?
148:         redirect_to @return_to
149:         session[:return_to] = nil
150:       else
151:         redirect_to edit_person_path(@person)
152:       end
153:     else
154:       render :new_login
155:     end
156:   end

Search for People

Params

  • name: case-insensitive SQL ‘like’ query
  • license: JSON and XML only
  • page: JSON and XML only

Returns

JSON and XML results are paginated with a page size of 10 :id, :first_name, :last_name, :date_of_birth, :license, :gender :aliases => :alias, :name :team => :name, :city, :state, :website :race_numbers => :value, :year :discipline => :only => :name

See source code of Api::People and Api::Base

[Source]

    # File app/controllers/people_controller.rb, line 26
26:   def index
27:     respond_to do |format|
28:       format.html { find_people }
29:       format.js { find_people }
30:       format.xml { render :xml => people_as_xml }
31:       format.json { render :json => people_as_json }
32:     end
33:   end

[Source]

    # File app/controllers/people_controller.rb, line 35
35:   def list
36:     people_list = ''
37:     Person.find_all_by_name_like(params['q']).each { |person| people_list += (person.name + '|' + person.id.to_s + "\n") }
38:     render :text => people_list
39:   end

Page to create a new login

[Source]

    # File app/controllers/people_controller.rb, line 79
79:   def new_login
80:     if current_person
81:       flash[:notice] = "You already have a login. You can your login or password on this page."
82:       return redirect_to(edit_person_path(current_person))
83:     end
84:     flash[:notice] = nil
85:     @person = Person.new
86:     @return_to = params[:return_to]
87:   end

[Source]

    # File app/controllers/people_controller.rb, line 41
41:   def show
42:     respond_to do |format|
43:       format.xml { render :xml => person_as_xml }
44:       format.json { render :json => person_as_json }
45:     end
46:   end

[Source]

    # File app/controllers/people_controller.rb, line 58
58:   def update
59:     if @person.update_attributes(params[:person])
60:       flash[:notice] = "Updated #{@person.name}"
61:       redirect_to edit_person_path(@person)
62:     else
63:       render :edit
64:     end
65:   end

[Validate]