diff --git a/.gitignore b/.gitignore index caf1445..39b1305 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ /lib/assets/* .DS_Store + +/config/initializers/secret_token.rb diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index 0a08ffc..5910387 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -50,12 +50,24 @@ class BikesController < ApplicationController end def bike_params - 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) + 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/clients_controller.rb b/app/controllers/clients_controller.rb new file mode 100644 index 0000000..19e3ff2 --- /dev/null +++ b/app/controllers/clients_controller.rb @@ -0,0 +1,65 @@ +class ClientsController < ApplicationController + before_action :set_client, only: [:show, :edit, :update, :destroy] + before_action :authenticate_user! + + def index + @clients = Client.all + end + + def show + end + + def new + @client = Client.new + end + + def edit + end + + def create + @client = Client.new(client_params) + respond_to do |format| + if @client.save + format.html { redirect_to @client, notice: 'Client was successfully created.' } + else + format.html { render action: 'new' } + end + end + end + + def update + respond_to do |format| + if @client.update(client_params) + format.html { redirect_to @client, notice: 'Client was successfully updated.' } + else + format.html { render action: 'edit' } + end + end + end + + def destroy + @client.destroy + respond_to do |format| + format.html { redirect_to clients_url } + end + end + + private + def set_client + @client = Client.find(params[:id]) + end + + def client_params + params.require(:client).permit( + :first_name, + :last_name, + :application_date, + :gender, + :age, + :weight, + :helmet, + :lock, + :agency, + :completion_date) + end +end diff --git a/app/models/client.rb b/app/models/client.rb new file mode 100644 index 0000000..998b2e4 --- /dev/null +++ b/app/models/client.rb @@ -0,0 +1,2 @@ +class Client < ActiveRecord::Base +end diff --git a/app/views/clients/_fields.html.haml b/app/views/clients/_fields.html.haml new file mode 100644 index 0000000..c884bde --- /dev/null +++ b/app/views/clients/_fields.html.haml @@ -0,0 +1,49 @@ +- disabled ||= false +.form-horizontal + .form-group + = f.label "First Name", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :first_name, class: "form-control", disabled: disabled + + .form-group + = f.label "Last Name", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :last_name, class: "form-control datepicker", disabled: disabled + + .form-group + = f.label "Gender", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :gender, class: "form-control", disabled: disabled + + .form-group + = f.label "Age", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :age, class: "form-control", disabled: disabled + + .form-group + = f.label "Weight", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :weight, class: "form-control", disabled: disabled + + .form-group + = f.label "Application Date:", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :application_date, class: "form-control", disabled: disabled + + .form-group + = f.label "Helmet", class: "col-sm-2 control-label" + .col-sm-10 + = f.check_box :helmet, class: "form-control", disabled: disabled + .form-group + = f.label "Lock", class: "col-sm-2 control-label" + .col-sm-10 + = f.check_box :lock, class: "form-control", disabled: disabled + + .form-group + = f.label "Agency", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :agency, class: "form-control", disabled: disabled + .form-group + = f.label "Completion Date:", class: "col-sm-2 control-label" + .col-sm-10 + = f.text_field :completion_date, class: "form-control datepicker", disabled: disabled diff --git a/app/views/clients/_form.html.haml b/app/views/clients/_form.html.haml new file mode 100644 index 0000000..41c61fe --- /dev/null +++ b/app/views/clients/_form.html.haml @@ -0,0 +1,12 @@ +.container + = form_for @client, html: {class: 'form-horizontal'} do |f| + - if @client.errors.any? + #error_explanation + %h2= pluralize(@client.errors.count, "error") + " prohibited this bike from being saved:" + %ul + - @client.errors.full_messages.each do |msg| + %li= msg + = render 'fields', f: f + .row + .actions.col-sm-offset-2 + = f.submit class: "btn btn-default" diff --git a/app/views/clients/edit.html.haml b/app/views/clients/edit.html.haml new file mode 100644 index 0000000..85480dc --- /dev/null +++ b/app/views/clients/edit.html.haml @@ -0,0 +1,6 @@ +.container + %h1 Editing client + = render 'form' + = link_to 'Show', @client + | + = link_to 'Back', clients_path diff --git a/app/views/clients/index.html.haml b/app/views/clients/index.html.haml new file mode 100644 index 0000000..a44d381 --- /dev/null +++ b/app/views/clients/index.html.haml @@ -0,0 +1,24 @@ +.container + %h1 Clients + + %table.table.table-striped.table-bordered.table-hover + %thead + %tr + %th First Name + %th Last Name + %th Agency + %th + %th + %th + %tbody + - @clients.each do |client| + %tr + %td= client.first_name + %td= client.last_name + %td= client.agency + %td= link_to 'Show', client + %td= link_to 'Edit', edit_client_path(client) + %td= link_to 'Destroy', client, method: :delete, data: { confirm: 'Are you sure?' } + + %br + = link_to ' + New Client', new_client_path, class: "btn btn-default" diff --git a/app/views/clients/new.html.haml b/app/views/clients/new.html.haml new file mode 100644 index 0000000..0197754 --- /dev/null +++ b/app/views/clients/new.html.haml @@ -0,0 +1,3 @@ +%h1 New Client += render 'form' += link_to 'Back', clients_path diff --git a/app/views/clients/show.html.haml b/app/views/clients/show.html.haml new file mode 100644 index 0000000..4e79350 --- /dev/null +++ b/app/views/clients/show.html.haml @@ -0,0 +1,7 @@ +.container + %p#notice= notice + = form_for(@client) do |f| + = render 'fields', f: f, disabled: true + = link_to 'Edit', edit_client_path(@client) + | + = link_to 'Back', clients_path diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index d159013..292511a 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -12,7 +12,7 @@ diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb deleted file mode 100644 index cfdc1e5..0000000 --- a/config/initializers/secret_token.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. - -# Make sure your secret_key_base is kept private -# if you're sharing your code publicly. -Bikedb::Application.config.secret_key_base = '55bed17e71286b1810e75f047637fd1acd64351fcdd5591ab83af67bdc628cb65958d98992a653268015aec9274a2e573b66fb5895d2bf86acd8a5c0e9d35813' diff --git a/config/routes.rb b/config/routes.rb index 8bc3e36..c626f38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,4 +3,5 @@ Bikedb::Application.routes.draw do root to: "static_pages#home" resources :bikes resources :volunteers + resources :clients end diff --git a/db/migrate/20140917003003_create_clients.rb b/db/migrate/20140917003003_create_clients.rb new file mode 100644 index 0000000..3278992 --- /dev/null +++ b/db/migrate/20140917003003_create_clients.rb @@ -0,0 +1,19 @@ +class CreateClients < ActiveRecord::Migration + def change + create_table :clients do |t| + t.string :first_name + t.string :last_name + t.date :application_date + t.string :gender + t.integer :age + t.integer :weight + t.boolean :helmet + t.boolean :lock + t.string :agency + t.date :completion_date + + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f2e3194..8b44742 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: 20140814020954) do +ActiveRecord::Schema.define(version: 20140917003003) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -37,6 +37,21 @@ ActiveRecord::Schema.define(version: 20140814020954) do t.text "mechanic" end + create_table "clients", force: true do |t| + t.string "first_name" + t.string "last_name" + t.date "application_date" + t.string "gender" + t.integer "age" + t.integer "weight" + t.boolean "helmet" + t.boolean "lock" + t.string "agency" + t.date "completion_date" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "users", force: true do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false diff --git a/spec/factories/clients.rb b/spec/factories/clients.rb new file mode 100644 index 0000000..50af5ee --- /dev/null +++ b/spec/factories/clients.rb @@ -0,0 +1,6 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :client do + end +end diff --git a/spec/models/client_spec.rb b/spec/models/client_spec.rb new file mode 100644 index 0000000..3c368cc --- /dev/null +++ b/spec/models/client_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Client do + pending "add some examples to (or delete) #{__FILE__}" +end