Class: QuestionnairesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- QuestionnairesController
- Includes:
- QuestionnairesControllable
- Defined in:
- app/controllers/questionnaires_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /apply POST /apply.json.
-
#destroy ⇒ Object
DELETE /apply DELETE /apply.json.
-
#edit ⇒ Object
GET /apply/edit.
- #logged_in ⇒ Object
-
#new ⇒ Object
GET /apply/new GET /apply/new.json.
-
#schools ⇒ Object
GET /apply/schools.
-
#show ⇒ Object
GET /apply GET /apply.json.
-
#update ⇒ Object
PUT /apply PUT /apply.json.
Instance Method Details
#create ⇒ Object
POST /apply POST /apply.json
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/questionnaires_controller.rb', line 63 def create if current_user.reload.questionnaire.present? return redirect_to questionnaires_path, notice: 'Application already exists.' end @questionnaire = Questionnaire.new(convert_school_name_to_id(questionnaire_params)) @questionnaire.user_id = current_user.id respond_to do |format| if @questionnaire.save @questionnaire.update_attribute(:acc_status, default_acc_status) format.html { redirect_to questionnaires_path } format.json { render json: @questionnaire, status: :created, location: @questionnaire } else format.html { render action: "new" } format.json { render json: @questionnaire.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /apply DELETE /apply.json
101 102 103 104 105 106 107 108 |
# File 'app/controllers/questionnaires_controller.rb', line 101 def destroy @questionnaire.destroy respond_to do |format| format.html { redirect_to questionnaires_url } format.json { head :no_content } end end |
#edit ⇒ Object
GET /apply/edit
58 59 |
# File 'app/controllers/questionnaires_controller.rb', line 58 def edit end |
#logged_in ⇒ Object
9 10 11 |
# File 'app/controllers/questionnaires_controller.rb', line 9 def logged_in authenticate_user! end |
#new ⇒ Object
GET /apply/new GET /apply/new.json
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/questionnaires_controller.rb', line 24 def new if current_user.questionnaire.present? return redirect_to questionnaires_path end @questionnaire = Questionnaire.new if session["devise.provider_data"] && session["devise.provider_data"]["info"] @skip_my_mlh_fields = true @questionnaire.tap do |q| q.first_name = session["devise.provider_data"]["info"]["first_name"] q.last_name = session["devise.provider_data"]["info"]["last_name"] q.phone = session["devise.provider_data"]["info"]["phone_number"] q.level_of_study = session["devise.provider_data"]["info"]["level_of_study"] q.major = session["devise.provider_data"]["info"]["major"] q.date_of_birth = session["devise.provider_data"]["info"]["date_of_birth"] q.shirt_size = session["devise.provider_data"]["info"]["shirt_size"] q.dietary_restrictions = session["devise.provider_data"]["info"]["dietary_restrictions"] q.special_needs = session["devise.provider_data"]["info"]["special_needs"] q.gender = session["devise.provider_data"]["info"]["gender"] school = School.where(name: session["devise.provider_data"]["info"]["school"]["name"]).first_or_create do |s| s.name = session["devise.provider_data"]["info"]["school"]["name"] end q.school_id = school.id end end respond_to do |format| format.html # new.html.erb format.json { render json: @questionnaire } end end |
#schools ⇒ Object
GET /apply/schools
111 112 113 114 115 116 117 118 |
# File 'app/controllers/questionnaires_controller.rb', line 111 def schools if params[:name].blank? || params[:name].length < 3 head :bad_request return end schools = School.where('name LIKE ?', "%#{params[:name]}%").order(questionnaire_count: :desc).limit(20).select(:name).all render json: schools.map(&:name) end |
#show ⇒ Object
GET /apply GET /apply.json
15 16 17 18 19 20 |
# File 'app/controllers/questionnaires_controller.rb', line 15 def show respond_to do |format| format.html # show.html.erb format.json { render json: @questionnaire } end end |
#update ⇒ Object
PUT /apply PUT /apply.json
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/controllers/questionnaires_controller.rb', line 84 def update update_params = questionnaire_params update_params = convert_school_name_to_id(update_params) respond_to do |format| if @questionnaire.update_attributes(update_params) format.html { redirect_to questionnaires_path, notice: 'Application was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @questionnaire.errors, status: :unprocessable_entity } end end end |