Skip to content

Commit

Permalink
basic coach-application, part of issue #110, missing:coach from signi…
Browse files Browse the repository at this point in the history
…n, validations, success-view, emails, admin
  • Loading branch information
magicjascha committed Mar 25, 2019
1 parent e9bef8e commit e6295f0
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/assets/javascripts/coach_applications.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/coach_applications.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the CoachApplications controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
25 changes: 25 additions & 0 deletions app/controllers/coach_applications_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class CoachApplicationsController < ApplicationController
before_action :find_event

def new
@coach_application = CoachApplication.new
@coach_application.coach = Coach.find_by_id(1)
@coach_application.event = @event
end

def create
@coach_application = CoachApplication.new(params.require(:coach_application).permit(:installationparty, :workshopday, :lightningtalk, :notes))
@coach_application.event = @event
@coach_application.coach = Coach.find_by_id(1)
if @coach_application.save
render html: 'Success'
else
render :new
end
end

private
def find_event
@event = Event.find(params[:event_id])
end
end
2 changes: 2 additions & 0 deletions app/helpers/coach_applications_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CoachApplicationsHelper
end
1 change: 1 addition & 0 deletions app/models/coach.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Coach < ApplicationRecord
belongs_to :user
accepts_nested_attributes_for :user
has_many :coach_applications
end
6 changes: 6 additions & 0 deletions app/models/coach_application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class CoachApplication < ApplicationRecord
belongs_to :coach
belongs_to :event
accepts_nested_attributes_for :coach
accepts_nested_attributes_for :event
end
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Event < ApplicationRecord
has_many :applications
has_many :coach_applications
before_create :copy_templates

validates :name, :place, :scheduled_at, :application_start, :application_end, :confirmation_date, :start_time, :end_time, presence: true
Expand Down
60 changes: 60 additions & 0 deletions app/views/coach_applications/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<%= form_for [@event, @coach_application] do |f| %>
<h2>I can help on the</h2>
<p class="note">Please select one or both.</p>
<p>
<%= f.check_box :installationparty %>
<%= f.label(:installationparty, "installation party") %>
</p>
<p>
<%= f.check_box :workshopday %>
<%= f.label(:workshopday, "workshop day") %>
</p>
<h2>Would you like to give a lightning talk? What topic do you have in mind?</h2>
<p class="note">The talk should be understandable for beginners and no longer than 5 minutes.</p>
<p>
<%= f.text_field :lightningtalk %>
</p>
<h2>Notes</h2>
<p class="note">including if you would like to help the organizers on the day or even become an organizer in the future</p>
<p>
<%= f.text_field :notes %>
</p>
<fieldset>
<h2>Personal Information</h2>
<%= f.fields_for :coach do |coaches_form| %>
<%= coaches_form.fields_for :user do |users_form| %>
<p><%= users_form.label(:email, "E-Mail Address") %><br>
<%= users_form.text_field :email %>
</p>
<% end %>
<p><%= coaches_form.label(:name, "Name") %></p><p class="note">No official name necessary, you can use the name you want to be called. Just be sure to remember what you picked. *</p>
<p><%= coaches_form.text_field :name %></p>
<p>
<%= coaches_form.check_box :female %>
<%= coaches_form.label(:female, "female/I have some female sex characteristics.") %>
</p>
</fieldset>
<fieldset>
<h2>Which language(s) can you teach in?</h2>
<p class="note">Please select one or both.</p>
<p>
<%= coaches_form.check_box :language_de %>
<%= coaches_form.label(:language_de, "German") %>
</p>
<p>
<%= coaches_form.check_box :language_en %>
<%= coaches_form.label(:language_en, "English") %>
</p>
</fieldset>
<fieldset>
<p>
<%= coaches_form.check_box :notifications %>
<%= coaches_form.label(:notifications, "Notifications about upcoming events") %>
</p>
<p class="note">It would be great to have you on board as a coach again.</p>
</fieldset>
<% end %>
<div class='button'>
<%= f.submit "Submit", class: 'commit', type: 'submit' %>
</div>
<% end %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
resources :coaches do
collection do
get 'signup', to: 'coaches#new'
get 'signin'
end
end
resources :events do
resources :applications do
get :confirm, to: "applications#confirm"
end
resources :coach_applications
end

namespace :admin do
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20190325103742_create_coach_applications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateCoachApplications < ActiveRecord::Migration[5.1]
def change
create_table :coach_applications do |t|
t.boolean :installationparty
t.boolean :workshopday
t.string :lightningtalk
t.string :notes
t.references :event, foreign_key: true
t.references :coach, foreign_key: true
t.timestamps
end
end
end
17 changes: 16 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20190318155532) do
ActiveRecord::Schema.define(version: 20190325103742) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -39,6 +39,19 @@
t.index ["event_id"], name: "index_applications_on_event_id"
end

create_table "coach_applications", force: :cascade do |t|
t.boolean "installationparty"
t.boolean "workshopday"
t.string "lightningtalk"
t.string "notes"
t.bigint "event_id"
t.bigint "coach_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["coach_id"], name: "index_coach_applications_on_coach_id"
t.index ["event_id"], name: "index_coach_applications_on_event_id"
end

create_table "coaches", force: :cascade do |t|
t.string "name"
t.boolean "language_de"
Expand Down Expand Up @@ -89,4 +102,6 @@
t.index ["remember_token"], name: "index_users_on_remember_token"
end

add_foreign_key "coach_applications", "coaches"
add_foreign_key "coach_applications", "events"
end
7 changes: 7 additions & 0 deletions test/controllers/coach_applications_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CoachApplicationsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
3 changes: 3 additions & 0 deletions test/factories.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FactoryGirl.define do
factory :coach_application do

end
factory :coach do
association :user
name "Swenja"
Expand Down
7 changes: 7 additions & 0 deletions test/models/coach_application_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class CoachApplicationTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit e6295f0

Please sign in to comment.