Browse Source

add volunteer table

vagrant
loos 11 years ago
parent
commit
65216e3835
  1. 10
      app/controllers/bikes_controller.rb
  2. 37
      app/controllers/volunteers_controller.rb
  3. 2
      app/models/volunteer.rb
  4. 45
      app/views/bikes/_fields.html.erb
  5. 1
      app/views/layouts/_navbar.html.erb
  6. 23
      app/views/volunteers/_fields.html.erb
  7. 23
      app/views/volunteers/_form.html.erb
  8. 0
      app/views/volunteers/edit.html.erb
  9. 9
      app/views/volunteers/index.html.erb
  10. 5
      app/views/volunteers/new.html.erb
  11. 9
      app/views/volunteers/show.html.erb
  12. 1
      config/routes.rb
  13. 23
      db/migrate/20140313000619_create_volunteers.rb
  14. 22
      db/schema.rb

10
app/controllers/bikes_controller.rb

@ -49,13 +49,17 @@ class BikesController < ApplicationController
end end
private private
# Use callbacks to share common setup or constraints between actions.
def set_bike def set_bike
@bike = Bike.find(params[:id]) @bike = Bike.find(params[:id])
end end
# Never trust parameters from the scary internet, only allow the white list through.
def bike_params 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
end end

37
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

2
app/models/volunteer.rb

@ -0,0 +1,2 @@
class Volunteer < ActiveRecord::Base
end

45
app/views/bikes/_fields.html.erb

@ -1,5 +1,12 @@
<% disabled ||= false %> <% disabled ||= false %>
<div class="form-group">
<%= f.label "Log Number", class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= f.text_field :log_number, class: "form-control", disabled: disabled %>
</div>
</div>
<div class="form-group"> <div class="form-group">
<%= f.label "Bike Entry Date:", class: "col-sm-2 control-label" %> <%= f.label "Bike Entry Date:", class: "col-sm-2 control-label" %>
<div class="col-sm-10"> <div class="col-sm-10">
@ -14,6 +21,29 @@
</div> </div>
</div> </div>
<div class="form-group">
<%= f.label "Color:", class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= f.text_field :color, class: "form-control", disabled: disabled %>
</div>
</div>
<div class="form-group">
<%= f.label "Top Tube Size:", class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= f.text_field :top_tube_size, class: "form-control", disabled: disabled %>
</div>
</div>
<div class="form-group">
<%= f.label "Seat Tube Size:", class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= f.text_field :seat_tube_size, class: "form-control", disabled: disabled %>
</div>
</div>
<div class="form-group"> <div class="form-group">
<%= f.label "Model:", class: "col-sm-2 control-label" %> <%= f.label "Model:", class: "col-sm-2 control-label" %>
<div class="col-sm-10"> <div class="col-sm-10">
@ -29,13 +59,10 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<%= f.label "Freecyclery?", class: "col-sm-offset-2 control-label" %> <%= f.label "Purpose:", class: "col-sm-2 control-label" %>
<%= f.check_box :freecyclery, disabled: disabled %> <div class="col-sm-10">
</div> <%= f.select :purpose, [["Freecyclery", "Freecyclery"], ["Sale", "Sale"]], class: "selectpicker", disabled: disabled %>
</div>
<div class="form-group">
<%= f.label "Sale?", class: "col-sm-offset-2 control-label" %>
<%= f.check_box :sale, disabled: disabled %>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -60,9 +87,9 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<%= f.label "Repaired by:", class: "col-sm-2 control-label" %> <%= f.label "Mechanic:", class: "col-sm-2 control-label" %>
<div class="col-sm-10"> <div class="col-sm-10">
<%= f.text_field :repaired_by, class: "form-control", disabled: disabled %> <%= f.text_field :mechanic, class: "form-control", disabled: disabled %>
</div> </div>
</div> </div>

1
app/views/layouts/_navbar.html.erb

@ -12,6 +12,7 @@
<div class="navbar-collapse collapse navbar-responsive-collapse" id='collapse-1'> <div class="navbar-collapse collapse navbar-responsive-collapse" id='collapse-1'>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li><%= link_to "Bike Tracker", bikes_path %></li> <li><%= link_to "Bike Tracker", bikes_path %></li>
<li><%= link_to "Volunteer Tracker", volunteers_path %></li>
</ul> </ul>
</div> </div>
</nav> </nav>

23
app/views/volunteers/_fields.html.erb

@ -0,0 +1,23 @@
<% disabled ||= false %>
<div class="form-group">
<%= f.label "Name", class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= f.text_field :name, class: "form-control", disabled: disabled %>
</div>
</div>
<div class="form-group">
<%= f.label "Email address:", class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= f.text_field :email, class: "form-control", disabled: disabled %>
</div>
</div>
<div class="form-group">
<%= f.label "Phone Number:", class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<%= f.text_field :phone, class: "form-control", disabled: disabled %>
</div>
</div>

23
app/views/volunteers/_form.html.erb

@ -0,0 +1,23 @@
<div class="container">
<%= form_for @volunteer, html: {class: 'form-horizontal'} do |f| %>
<% if @volunteer.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@volunteer.errors.count, "error") %> prohibited this volunteer from being saved:</h2>
<ul>
<% @volunteer.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= render 'fields', f: f %>
<div class="row">
<div class="actions col-sm-offset-2">
<%= f.submit class: "btn btn-default" %>
</div>
</div>
<% end %>
</div>

0
app/views/volunteers/edit.html.erb

9
app/views/volunteers/index.html.erb

@ -0,0 +1,9 @@
<div class="container">
<h1>Volunteer Listing</h1>
<% @volunteers.each do |volunteer| %>
<%= volunteer.name %>
<br>
<% end %>
<%= link_to '+ Add Volunteer', new_volunteer_path, class: "btn btn-default" %>
</div>

5
app/views/volunteers/new.html.erb

@ -0,0 +1,5 @@
<h1>New Volunteer</h1>
<%= render 'form' %>
<%= link_to 'Back', volunteers_path %>

9
app/views/volunteers/show.html.erb

@ -0,0 +1,9 @@
<div class="container">
<p id="notice"><%= notice %></p>
<%= form_for(@volunteer) do |f| %>
<%= render 'fields', f: f, disabled: true %>
<% end %>
<%= link_to 'Edit', edit_volunteer_path(@volunteer) %> |
<%= link_to 'Back', volunteer_path %>
</div>

1
config/routes.rb

@ -1,4 +1,5 @@
Bikedb::Application.routes.draw do Bikedb::Application.routes.draw do
root "static_pages#home" root "static_pages#home"
resources :bikes resources :bikes
resources :volunteers
end end

23
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

22
db/schema.rb

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -37,4 +37,24 @@ ActiveRecord::Schema.define(version: 20140312232550) do
t.text "mechanic" t.text "mechanic"
end 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 end

Loading…
Cancel
Save