polish application

and add cancellation
This commit is contained in:
Torsten Ruger 2016-05-18 16:35:14 +03:00
parent 0a46f2dc46
commit 77e3583120
7 changed files with 89 additions and 43 deletions

View File

@ -1,5 +1,5 @@
class AppliesController < ApplicationController
before_action :set_apply, only: [:show , :create]
before_action :set_apply, only: [:show , :create , :cancel]
# GET /applies/1
# GET /applies/1.json
@ -7,21 +7,21 @@ class AppliesController < ApplicationController
render @apply.new_record? ? :edit : :show
end
# POST /applies
# POST /applies.json
def create
@apply = Apply.new(apply_params)
@apply.user = current_user
respond_to do |format|
if @apply.save
format.html { redirect_to application_path, notice: 'ApplicationController was successfully created.' }
format.json { render :show, status: :created, location: @apply }
else
format.html { render :edit }
format.json { render json: @apply.errors, status: :unprocessable_entity }
end
if @apply.save
redirect_to application_path, notice: 'Application was successfully submitted. Your will receive further instructions from us within a week'
else
render :edit
end
end
def cancel
@apply.delete
redirect_to edit_user_registration_path, alert: 'Application was canceled.'
end
private
@ -32,6 +32,7 @@ class AppliesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def apply_params
params.require(:apply).permit(:primary_choice_course_id, :secondary_choice_course_id, :comment, :user_id, :sent)
params.require(:apply).permit(:primary_choice_course_id, :secondary_choice_course_id, :comment,
:discount_code , :user_id, :sent)
end
end

View File

@ -1,6 +1,6 @@
module AppliesHelper
def course_select
Course.all.order(:name).map { |c| [c.name, c.id ] }
Course.all.order(:name).map { |c| [c.full_name, c.id ] }
end
def plan_select

View File

@ -1,5 +1,7 @@
class Apply < ActiveRecord::Base
belongs_to :user
belongs_to :primary_choice_course , class_name: :Course
belongs_to :secondary_choice_course , class_name: :Course
validate :primary_choice_course_id
validates_presence_of :primary_choice_course_id
end

View File

@ -1,2 +1,8 @@
class Course < ActiveRecord::Base
def full_name
name = self.name
name += "(#{self.extra})" unless self.extra.blank?
name + " starts " + self.start.to_date.to_s
end
end

View File

@ -1,23 +1,26 @@
= render 'users/submenu'
.authform
%h1 Create your application
%section.padding-xxs
.container
.authform
%h1 Create your application
= simple_form_for(@apply , url: application_path ) do |f|
= f.error_notification
= simple_form_for(@apply , url: application_path ) do |f|
= f.error_notification
.form-input
= f.label "Primary choice to start"
= f.select :primary_choice_course_id , course_select #, :prompt => "Select" #, :include_blank => true
.form-input
= f.label "Optional secondary choice to start"
= f.select :secondary_choice_course_id , course_select
.form-input
= f.label "Payment plan (prices for 2 week modules)"
= f.select :plan , plan_select.invert
.form-input
= f.input :discount_code , label: "Optional code determines prearranged discount"
.form-input
= f.input :comment
.form-input
= f.label "Primary choice to start"
= f.select :primary_choice_course_id , course_select
.form-input
= f.label "Optional secondary choice to start"
= f.select :secondary_choice_course_id , course_select , :prompt => "Optionally select second"
.form-input
= f.label "Payment plan (prices for 2 week modules, course has 4 modules)"
= f.select :plan , plan_select.invert
.form-input
= f.input :discount_code , label: "Optional code determines prearranged discount"
.form-input
= f.input :comment
.form-actions
= f.button :submit , "Create Application" , class: "btn btn-primary"
.form-actions
= f.label "By pressing submit you acknowledge the terms & conditions and payment policy."
= f.button :submit , "Create Application" , class: "btn btn-primary"

View File

@ -1,11 +1,44 @@
%p#notice= notice
= render 'users/submenu'
%section.padding-xxs
.container
.row
.col-md-2
.col-md-8
%h3 Application is submitted
%p
We have received your application on the
=@apply.created_at.to_date.to_s
and are processing it. We will be in touch by email.
%p#notice= notice
%p
%p
%b Primary choice:
= @apply.primary_choice_course_id
%p
%b Secondary choice:
= @apply.secondary_choice_course_id
%p
%b Comment:
= @apply.comment
%table
%tr
%td
%b Primary choice:
%td= @apply.primary_choice_course.full_name
%tr
%td
%b Secondary choice:
%td
= @apply.secondary_choice_course.full_name if @apply.secondary_choice_course
%tr
%td Discount:
%td= @apply.discount_code || "None"
%tr
%td Comment:
%td= @apply.comment || "None"
.authform
%h3 Cancelling your application
%p
You may revoke your application at any point. We ask you to give a reason for doing so,
and depending on that reason this may affect future applications.
= simple_form_for(@apply , url: cancel_application_path , method: :post) do |f|
.form-input
= f.label "Reason for cancellation"
= text_area_tag :reason , nil , class: "form-control"
.form-actions
= f.button :submit , "Cancel Application" , class: "btn btn-danger"

View File

@ -15,6 +15,7 @@ Rails.application.routes.draw do
resource :resume , except: [:destroy , :new , :edit]
get :application , to: "applies#show"
post :application , to: "applies#create"
post :cancel_application , to: "applies#cancel"
root to: 'high_voltage/pages#show' , id: 'index'