Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add User & Coach validations #81

Merged
merged 1 commit into from
Oct 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions app/assets/stylesheets/coaches.scss

This file was deleted.

3 changes: 0 additions & 3 deletions app/assets/stylesheets/tutorials.scss

This file was deleted.

1 change: 0 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def edit
# POST /users
def create
@user = User.new(user_params)

if @user.save
@user.create_tutorial
redirect_to user_tutorial_path(@user,@user.tutorial), notice: 'User was successfully created.'
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/coaches_helper.rb

This file was deleted.

9 changes: 9 additions & 0 deletions app/models/coach.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Coach < ApplicationRecord
validates :first_name, presence: true
validates :first_name, length: { minimum: 2 }
validates :first_name, length: { minimum: 30 }
validates :last_name, presence: true
validates :last_name, length: { minimum: 2 }
validates :last_name, length: { minimum: 30 }
validates :email, presence: true
validates :days, presence: true
validates :operating_system, presence: true
end
12 changes: 12 additions & 0 deletions app/models/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ class Question < ApplicationRecord
# has_many :answers
# has_many :users, through: :answers
belongs_to :user, inverse_of: :question
validates :newbie, presence: true
validates :tutorials, presence: true
validates :program, presence: true
validates :website, presence: true
validates :work, presence: true
validates :bootcamp, presence: true
validates :compsci, presence: true
validates :rlsgrl_rlsbrg, presence: true
validates :continue, presence: true
validates :support, presence: true
validates :experience, presence: true
validates :experience, length: { maximum: 500 }
end
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ class User < ApplicationRecord
has_one :question, inverse_of: :user, dependent: :destroy
has_one :tutorial, dependent: :destroy
accepts_nested_attributes_for :question
validates :first_name, presence: true
validates :first_name, length: { minimum: 2 }
validates :first_name, length: { minimum: 30 }
validates :last_name, presence: true
validates :last_name, length: { minimum: 2 }
validates :last_name, length: { minimum: 30 }
validates :email, presence: true
validates :over_21, presence: true
validates :operating_system, presence: true
end
17 changes: 8 additions & 9 deletions app/views/coaches/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
<%= f.input :twitter, placeholder: "https://twitter.com/your-user-name", required: false %>
<%= f.input :github, placeholder: "https://github.com/your-user-name", required: false %>
<%= f.input :job, label: "Job Title, Company" %>

<p>Check box to indicate an answer of YES to the following questions:</p>
<%= f.input :work_at_sponsoring_company,label: "I work at Spokeo?" %>
<%= f.input :attended_as_student, label: "I attended Rails Girls as a student. (or Railsbridge)" %>
<hr/>
<%= f.input :work_at_sponsoring_company,label: "I work at Spokeo?", as: :radio_buttons %>
<%= f.input :attended_as_student, label: "I attended Rails Girls as a student. (or Railsbridge)", as: :radio_buttons %>
<p>I coached RailsGirlsLA on:</p>
<%= f.input :coach_april_13_pivotal, label: "April 2013 at Pivotal" %>
<%= f.input :coach_march_14_invpasadena, label: "March 2014 at Innovate Pasadena" %>
<%= f.input :coach_april_15_pivotal, label: "April 2015 at Pivotal" %>
<%= f.input :coach_august_15_spokeo, label: "August 2015 at Spokeo" %>
<%= f.input :coach_march_16_zest, label: "March 2016 at Zest Finance" %></p>
<%= f.input :coach_april_13_pivotal, label: "April 2013 at Pivotal", as: :radio_buttons %>
<%= f.input :coach_march_14_invpasadena, label: "March 2014 at Innovate Pasadena", as: :radio_buttons %>
<%= f.input :coach_april_15_pivotal, label: "April 2015 at Pivotal", as: :radio_buttons %>
<%= f.input :coach_august_15_spokeo, label: "August 2015 at Spokeo", as: :radio_buttons %>
<%= f.input :coach_march_16_zest, label: "March 2016 at Zest Finance", as: :radio_buttons %></p>

<%= f.input :notes, label: "Anything you want to add or ask. :) List your past students if you can remember them." %>
</div>
Expand Down
24 changes: 12 additions & 12 deletions app/views/questions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
<%= f.error_notification %>

<div class="form-inputs">
<%= f.input :newbie, label: "I am a total newbie :)" %>
<%= f.input :html_css, label: "I am familiar with HTML / CSS" %>
<%= f.input :tutorials, label: "I have done online Ruby / Rails tutorials" %>
<%= f.input :study_group, label: "I attend a Study Group" %>
<%= f.input :program, label: "I have written a program (any language)" %>
<%= f.input :website, label: "I have created a website and launched it on the web" %>
<%= f.input :work, label: "I currently work in tech" %>
<%= f.input :bootcamp, label: "I have attended an immersive bootcamp program" %>
<%= f.input :newbie, label: "I am a total newbie :)", required: true, as: :radio_buttons %>
<%= f.input :html_css, label: "I am familiar with HTML / CSS", required: true, as: :radio_buttons %>
<%= f.input :tutorials, label: "I have done online Ruby / Rails tutorials", required: true, as: :radio_buttons %>
<%= f.input :study_group, label: "I attend a Study Group", required: true, as: :radio_buttons %>
<%= f.input :program, label: "I have written a program (any language)", required: true, as: :radio_buttons %>
<%= f.input :website, label: "I have created a website and launched it on the web", required: true, as: :radio_buttons %>
<%= f.input :work, label: "I currently work in tech", required: true, as: :radio_buttons %>
<%= f.input :bootcamp, label: "I have attended an immersive bootcamp program" , required: true, as: :radio_buttons %>
<%= f.input :compsci, label: "I have or am getting a CS degree" %>
<%= f.input :rlsgrl_rlsbrg, label: "I have attended Rails Girls / Railsbridge" %>
<%= f.input :continue, label: "Do you think you will continue learning to program after the workshop?" %>
<%= f.input :support, label: "Do you have any people to support you with this goal?" %>
<%= f.input :experience, label: "Previous Experience. Do you have any previous programming experience? Please explain. What languages? For how long? What did you make? In school or on your own? Do you currently program? Did you attend a code school? This helps us group students when working in small groups." %>
<%= f.input :rlsgrl_rlsbrg, label: "I have attended Rails Girls / Railsbridge" , required: true, as: :radio_buttons %>
<%= f.input :continue, label: "Do you think you will continue learning to program after the workshop?" , required: true, as: :radio_buttons %>
<%= f.input :support, label: "Do you have any people to support you with this goal?" , required: true, as: :radio_buttons %>
<%= f.input :experience, label: "Previous Experience. Do you have any previous programming experience? Please explain. What languages? For how long? What did you make? In school or on your own? Do you currently program? Did you attend a code school? This helps us group students when working in small groups.", required: true, as: :radio_buttons %>
</div>
<div class="form-actions">
<%= f.button :submit, "SUBMIT ♥", class: "rg-button" %>
Expand Down
9 changes: 4 additions & 5 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<div style="background-color:#ccc09e; padding:10px">
<%= simple_form_for @user do |f| %>
<% if user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>

<% if @user.errors.any? %>
<div class="alert alert-danger" id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% user.errors.full_messages.each do |message| %>
<% @user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
Expand Down