From 65216e3835cf4b4a08a887e4b47a515b2a59179c Mon Sep 17 00:00:00 2001 From: loos Date: Wed, 12 Mar 2014 19:37:51 -0500 Subject: [PATCH] add volunteer table --- app/controllers/bikes_controller.rb | 10 +++-- app/controllers/volunteers_controller.rb | 37 +++++++++++++++ app/models/volunteer.rb | 2 + app/views/bikes/_fields.html.erb | 45 +++++++++++++++---- app/views/layouts/_navbar.html.erb | 1 + app/views/volunteers/_fields.html.erb | 23 ++++++++++ app/views/volunteers/_form.html.erb | 23 ++++++++++ app/views/volunteers/edit.html.erb | 0 app/views/volunteers/index.html.erb | 9 ++++ app/views/volunteers/new.html.erb | 5 +++ app/views/volunteers/show.html.erb | 9 ++++ config/routes.rb | 1 + .../20140313000619_create_volunteers.rb | 23 ++++++++++ db/schema.rb | 22 ++++++++- 14 files changed, 197 insertions(+), 13 deletions(-) create mode 100644 app/controllers/volunteers_controller.rb create mode 100644 app/models/volunteer.rb create mode 100644 app/views/volunteers/_fields.html.erb create mode 100644 app/views/volunteers/_form.html.erb create mode 100644 app/views/volunteers/edit.html.erb create mode 100644 app/views/volunteers/index.html.erb create mode 100644 app/views/volunteers/new.html.erb create mode 100644 app/views/volunteers/show.html.erb create mode 100644 db/migrate/20140313000619_create_volunteers.rb diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index 8816a6e..6dd8754 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -49,13 +49,17 @@ class BikesController < ApplicationController end private - # Use callbacks to share common setup or constraints between actions. def set_bike @bike = Bike.find(params[:id]) end - # Never trust parameters from the scary internet, only allow the white list through. def bike_params - params.require(:bike).permit(:entry_date, :brand, :model, :type, :color, :frame_size, :freecyclery, :sale, :serial_number, :notes, :tag_info, :repaired_by, :completion_date, :price, :created_at, :updated_at) + params.require(:bike).permit(:entry_date, :brand, :model, + :type, :color, :frame_size, + :log_number, :purpose, :serial_number, + :notes, :tag_info, :mechanic, + :completion_date, :price, + :top_tube_size, :seat_tube_size, + :created_at, :updated_at) end end diff --git a/app/controllers/volunteers_controller.rb b/app/controllers/volunteers_controller.rb new file mode 100644 index 0000000..cdf9416 --- /dev/null +++ b/app/controllers/volunteers_controller.rb @@ -0,0 +1,37 @@ +class VolunteersController < ApplicationController + before_action :set_volunteer, only: [:show, :edit, :update, :destroy] + + def index + @volunteers = Volunteer.all + end + def show; end + def new + @volunteer = Volunteer.new + end + def edit; end + + def create + @volunteer = Volunteer.new(volunteer_params) + respond_to do |format| + if @volunteer.save + format.html { redirect_to @volunteer, notice: 'Volunteer was successfully created.' } + format.json { render action: 'show', status: :created, location: @bike } + else + format.html { render action: 'new' } + format.json { render json: @volunteer.errors, status: :unprocessable_entity } + end + end + end + + def update; end + def destroy; end + + private + def set_volunteer + @volunteer = Volunteer.find(params[:id]) + end + + def volunteer_params + params.require(:volunteer).permit(:name, :email, :phone) + end +end diff --git a/app/models/volunteer.rb b/app/models/volunteer.rb new file mode 100644 index 0000000..bbac347 --- /dev/null +++ b/app/models/volunteer.rb @@ -0,0 +1,2 @@ +class Volunteer < ActiveRecord::Base +end diff --git a/app/views/bikes/_fields.html.erb b/app/views/bikes/_fields.html.erb index 7c5ede5..ec64881 100644 --- a/app/views/bikes/_fields.html.erb +++ b/app/views/bikes/_fields.html.erb @@ -1,5 +1,12 @@ <% disabled ||= false %> +
+ <%= f.label "Log Number", class: "col-sm-2 control-label" %> +
+ <%= f.text_field :log_number, class: "form-control", disabled: disabled %> +
+
+
<%= f.label "Bike Entry Date:", class: "col-sm-2 control-label" %>
@@ -14,6 +21,29 @@
+
+ <%= f.label "Color:", class: "col-sm-2 control-label" %> +
+ <%= f.text_field :color, class: "form-control", disabled: disabled %> +
+
+ + +
+ <%= f.label "Top Tube Size:", class: "col-sm-2 control-label" %> +
+ <%= f.text_field :top_tube_size, class: "form-control", disabled: disabled %> +
+
+ + +
+ <%= f.label "Seat Tube Size:", class: "col-sm-2 control-label" %> +
+ <%= f.text_field :seat_tube_size, class: "form-control", disabled: disabled %> +
+
+
<%= f.label "Model:", class: "col-sm-2 control-label" %>
@@ -29,13 +59,10 @@
- <%= f.label "Freecyclery?", class: "col-sm-offset-2 control-label" %> - <%= f.check_box :freecyclery, disabled: disabled %> -
- -
- <%= f.label "Sale?", class: "col-sm-offset-2 control-label" %> - <%= f.check_box :sale, disabled: disabled %> + <%= f.label "Purpose:", class: "col-sm-2 control-label" %> +
+ <%= f.select :purpose, [["Freecyclery", "Freecyclery"], ["Sale", "Sale"]], class: "selectpicker", disabled: disabled %> +
@@ -60,9 +87,9 @@
- <%= f.label "Repaired by:", class: "col-sm-2 control-label" %> + <%= f.label "Mechanic:", class: "col-sm-2 control-label" %>
- <%= f.text_field :repaired_by, class: "form-control", disabled: disabled %> + <%= f.text_field :mechanic, class: "form-control", disabled: disabled %>
diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index 3272215..dd2ebb5 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -12,6 +12,7 @@ diff --git a/app/views/volunteers/_fields.html.erb b/app/views/volunteers/_fields.html.erb new file mode 100644 index 0000000..5a71aa6 --- /dev/null +++ b/app/views/volunteers/_fields.html.erb @@ -0,0 +1,23 @@ +<% disabled ||= false %> + +
+ <%= f.label "Name", class: "col-sm-2 control-label" %> +
+ <%= f.text_field :name, class: "form-control", disabled: disabled %> +
+
+ +
+ <%= f.label "Email address:", class: "col-sm-2 control-label" %> +
+ <%= f.text_field :email, class: "form-control", disabled: disabled %> +
+
+ +
+ <%= f.label "Phone Number:", class: "col-sm-2 control-label" %> +
+ <%= f.text_field :phone, class: "form-control", disabled: disabled %> +
+
+ diff --git a/app/views/volunteers/_form.html.erb b/app/views/volunteers/_form.html.erb new file mode 100644 index 0000000..8799ba7 --- /dev/null +++ b/app/views/volunteers/_form.html.erb @@ -0,0 +1,23 @@ +
+ <%= form_for @volunteer, html: {class: 'form-horizontal'} do |f| %> + <% if @volunteer.errors.any? %> +
+

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

+ +
    + <% @volunteer.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + + <%= render 'fields', f: f %> + +
+
+ <%= f.submit class: "btn btn-default" %> +
+
+ <% end %> +
diff --git a/app/views/volunteers/edit.html.erb b/app/views/volunteers/edit.html.erb new file mode 100644 index 0000000..e69de29 diff --git a/app/views/volunteers/index.html.erb b/app/views/volunteers/index.html.erb new file mode 100644 index 0000000..41ff977 --- /dev/null +++ b/app/views/volunteers/index.html.erb @@ -0,0 +1,9 @@ +
+

Volunteer Listing

+ <% @volunteers.each do |volunteer| %> + <%= volunteer.name %> +
+ <% end %> + <%= link_to '+ Add Volunteer', new_volunteer_path, class: "btn btn-default" %> +
+ diff --git a/app/views/volunteers/new.html.erb b/app/views/volunteers/new.html.erb new file mode 100644 index 0000000..82b4549 --- /dev/null +++ b/app/views/volunteers/new.html.erb @@ -0,0 +1,5 @@ +

New Volunteer

+ +<%= render 'form' %> + +<%= link_to 'Back', volunteers_path %> diff --git a/app/views/volunteers/show.html.erb b/app/views/volunteers/show.html.erb new file mode 100644 index 0000000..658b0fc --- /dev/null +++ b/app/views/volunteers/show.html.erb @@ -0,0 +1,9 @@ +
+

<%= notice %>

+ <%= form_for(@volunteer) do |f| %> + <%= render 'fields', f: f, disabled: true %> + <% end %> + + <%= link_to 'Edit', edit_volunteer_path(@volunteer) %> | + <%= link_to 'Back', volunteer_path %> +
diff --git a/config/routes.rb b/config/routes.rb index 37b1022..4980a1e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Bikedb::Application.routes.draw do root "static_pages#home" resources :bikes + resources :volunteers end diff --git a/db/migrate/20140313000619_create_volunteers.rb b/db/migrate/20140313000619_create_volunteers.rb new file mode 100644 index 0000000..51886fb --- /dev/null +++ b/db/migrate/20140313000619_create_volunteers.rb @@ -0,0 +1,23 @@ +class CreateVolunteers < ActiveRecord::Migration + def change + create_table :volunteers do |t| + t.string :name + t.string :email + t.string :phone + t.date :orientation_date + t.integer :other_volunteer_hours + t.text :referral + t.text :reason + t.text :skills + t.text :wants + t.boolean :interested_in_improving + t.boolean :available_weekends + t.boolean :available_weekdays + t.boolean :available_shorter_hours + t.boolean :available_longer_hours + t.boolean :flexible + t.text :questions + t.text :improve_orientation + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 355e7f6..5ec7213 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140312232550) do +ActiveRecord::Schema.define(version: 20140313000619) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -37,4 +37,24 @@ ActiveRecord::Schema.define(version: 20140312232550) do t.text "mechanic" end + create_table "volunteers", force: true do |t| + t.string "name" + t.string "email" + t.string "phone" + t.date "orientation_date" + t.integer "other_volunteer_hours" + t.text "referral" + t.text "reason" + t.text "skills" + t.text "wants" + t.boolean "interested_in_improving" + t.boolean "available_weekends" + t.boolean "available_weekdays" + t.boolean "available_shorter_hours" + t.boolean "available_longer_hours" + t.boolean "flexible" + t.text "questions" + t.text "improve_orientation" + end + end