From d447dfb00a09463affd162066ebc8d1cb2803f6e Mon Sep 17 00:00:00 2001 From: jendiamond Date: Fri, 7 Oct 2016 17:21:01 -0700 Subject: [PATCH] Add User & Coach validations Add validations so Users(Students) & Coaches submit all necessary information Delete extra lines Delete unused files --- app/assets/stylesheets/coaches.scss | 3 --- app/assets/stylesheets/tutorials.scss | 3 --- app/controllers/users_controller.rb | 1 - app/helpers/coaches_helper.rb | 2 -- app/models/coach.rb | 9 +++++++++ app/models/question.rb | 12 ++++++++++++ app/models/user.rb | 9 +++++++++ app/views/coaches/_form.html.erb | 17 ++++++++--------- app/views/questions/_form.html.erb | 24 ++++++++++++------------ app/views/users/_form.html.erb | 9 ++++----- 10 files changed, 54 insertions(+), 35 deletions(-) delete mode 100644 app/assets/stylesheets/coaches.scss delete mode 100644 app/assets/stylesheets/tutorials.scss delete mode 100644 app/helpers/coaches_helper.rb diff --git a/app/assets/stylesheets/coaches.scss b/app/assets/stylesheets/coaches.scss deleted file mode 100644 index 3347e7f..0000000 --- a/app/assets/stylesheets/coaches.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the Coaches controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/tutorials.scss b/app/assets/stylesheets/tutorials.scss deleted file mode 100644 index bbeba57..0000000 --- a/app/assets/stylesheets/tutorials.scss +++ /dev/null @@ -1,3 +0,0 @@ -// Place all the styles related to the Tutorials controller here. -// They will automatically be included in application.css. -// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index aa6f750..7fd5e9f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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.' diff --git a/app/helpers/coaches_helper.rb b/app/helpers/coaches_helper.rb deleted file mode 100644 index 4a533de..0000000 --- a/app/helpers/coaches_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module CoachesHelper -end diff --git a/app/models/coach.rb b/app/models/coach.rb index 4c7b1ab..da66878 100644 --- a/app/models/coach.rb +++ b/app/models/coach.rb @@ -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 diff --git a/app/models/question.rb b/app/models/question.rb index 4b21055..0c399cb 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 9f7a217..2046614 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/coaches/_form.html.erb b/app/views/coaches/_form.html.erb index fa74619..e3564e7 100644 --- a/app/views/coaches/_form.html.erb +++ b/app/views/coaches/_form.html.erb @@ -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" %> - -

Check box to indicate an answer of YES to the following questions:

- <%= 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)" %> +
+ <%= 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 %>

I coached RailsGirlsLA on:

- <%= 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" %>

+ <%= 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 %>

<%= f.input :notes, label: "Anything you want to add or ask. :) List your past students if you can remember them." %> diff --git a/app/views/questions/_form.html.erb b/app/views/questions/_form.html.erb index 5ade71d..2a01d95 100644 --- a/app/views/questions/_form.html.erb +++ b/app/views/questions/_form.html.erb @@ -6,19 +6,19 @@ <%= f.error_notification %>
- <%= 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 %>
<%= f.button :submit, "SUBMIT ♥", class: "rg-button" %> diff --git a/app/views/users/_form.html.erb b/app/views/users/_form.html.erb index 7d78d38..cb5ff2d 100644 --- a/app/views/users/_form.html.erb +++ b/app/views/users/_form.html.erb @@ -1,11 +1,10 @@
<%= simple_form_for @user do |f| %> - <% if user.errors.any? %> -
-

<%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:

- + <% if @user.errors.any? %> +
+

<%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:

    - <% user.errors.full_messages.each do |message| %> + <% @user.errors.full_messages.each do |message| %>
  • <%= message %>
  • <% end %>