diff --git a/app/controllers/contracts_controller.rb b/app/controllers/contracts_controller.rb new file mode 100644 index 0000000..eb6a04c --- /dev/null +++ b/app/controllers/contracts_controller.rb @@ -0,0 +1,50 @@ +class ContractsController < ApplicationController + load_and_authorize_resource :contract + before_filter :authenticate_user! + layout 'resources' + + def index + end + + def show + end + + def new + end + + def edit + end + + def create + respond_to do |format| + if @contract.save + format.html { redirect_to Contract, :notice => 'Contract was successfully created.' } + format.json { render :json => @contract, :status => :created, :location => @contract } + else + format.html { render :action => "new" } + format.json { render :json => @contract.errors, :status => :unprocessable_entity } + end + end + end + + def update + respond_to do |format| + if @contract.update_attributes(params[:contract]) + format.html { redirect_to Contract, :notice => 'Contract was successfully updated.' } + format.json { head :no_content } + else + format.html { render :action => "edit" } + format.json { render :json => @contract.errors, :status => :unprocessable_entity } + end + end + end + + def destroy + @contract.destroy + + respond_to do |format| + format.html { redirect_to contracts_url } + format.json { head :no_content } + end + end +end diff --git a/app/models/contract.rb b/app/models/contract.rb new file mode 100644 index 0000000..d7d58f4 --- /dev/null +++ b/app/models/contract.rb @@ -0,0 +1,12 @@ +class Contract < ActiveRecord::Base + belongs_to :user + attr_accessible :user_id, :first_name, :last_name, :signed_at, :document_file_name, :document_content_type, :document_file_size, :document_updated_at + + validates_presence_of :first_name, :last_name, :signed_at + + has_attached_file :document, { :styles => { :medium => "300x300>"}, + :storage => :s3, + :s3_credentials => Rails.root.join('config', 's3.yml'), + :path => ":attachment/:id/:style.:extension", + :bucket => 'Toolshare' } #TODO: move to local storage +end diff --git a/app/views/contracts/_form.html.erb b/app/views/contracts/_form.html.erb new file mode 100644 index 0000000..e4a6f79 --- /dev/null +++ b/app/views/contracts/_form.html.erb @@ -0,0 +1,36 @@ +<%= form_for(@contract, html: {class: "col-sm-6"}) do |f| %> + <% if @contract.errors.any? %> +
+

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

+ + +
+ <% end %> + +

+ <%= f.label :first_name %>
+ <%= f.text_field :first_name, class: "form-control" %> +

+

+ <%= f.label :last_name %>
+ <%= f.text_field :last_name, class: "form-control" %> +

+ +

+ <%= f.label :signed_at %>
+ <%= f.date_select :signed_at, class: "form-control" %> +

+ +

+ <%= f.label :document %>
+ <%= f.file_field :document %> +

+ +

+ <%= f.submit nil, class: "btn btn-primary" %> +

+<% end %> diff --git a/app/views/contracts/index.html.erb b/app/views/contracts/index.html.erb new file mode 100644 index 0000000..05f4670 --- /dev/null +++ b/app/views/contracts/index.html.erb @@ -0,0 +1,21 @@ +
+

Contracts + <%= link_to 'Add Contract', new_contract_path, :class => "btn btn-success" if can? :create, Contract %> +

+
+ +
+ <% @contracts.sort_by{|r| [r.last_name] }.each do |contract| %> +
+
+

+ <%= contract.last_name %> + <%= contract.first_name %> +

+
+
+ <% end %> +
+ +
+ diff --git a/app/views/contracts/new.html.erb b/app/views/contracts/new.html.erb new file mode 100644 index 0000000..b8104b0 --- /dev/null +++ b/app/views/contracts/new.html.erb @@ -0,0 +1,4 @@ +

New Contract +<%= link_to 'Back', contracts_path, class: "btn btn-default" %> +

+<%= render 'form' %> diff --git a/config/routes.rb b/config/routes.rb index f0f58c9..d0bfcec 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,6 +19,8 @@ Dooraccess::Application.routes.draw do resources :certifications + resources :contracts + devise_for :users, :skip => :registrations devise_scope :user do resource :registration, diff --git a/db/migrate/20140227095847_create_contracts.rb b/db/migrate/20140227095847_create_contracts.rb new file mode 100644 index 0000000..28ed0ea --- /dev/null +++ b/db/migrate/20140227095847_create_contracts.rb @@ -0,0 +1,16 @@ +class CreateContracts < ActiveRecord::Migration + def change + create_table :contracts do |t| + t.integer :user_id + t.datetime :first_name + t.datetime :last_name + t.datetime :signed_at + t.string :document_file_name + t.string :document_content_type + t.integer :document_file_size + t.datetime :document_updated_at + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 33f5484..ef73cd0 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,34 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140223060554) do +ActiveRecord::Schema.define(:version => 20140227095847) do + + create_table "admins", :force => true do |t| + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "password_salt", :default => "", :null => false + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "reset_password_token" + t.string "remember_token" + t.datetime "remember_created_at" + t.integer "sign_in_count", :default => 0 + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.integer "failed_attempts", :default => 0 + t.string "unlock_token" + t.datetime "locked_at" + t.datetime "created_at" + t.datetime "updated_at" + t.string "name" + end + + add_index "admins", ["confirmation_token"], :name => "index_admins_on_confirmation_token", :unique => true + add_index "admins", ["email"], :name => "index_admins_on_email", :unique => true + add_index "admins", ["reset_password_token"], :name => "index_admins_on_reset_password_token", :unique => true create_table "cards", :force => true do |t| t.string "card_number" @@ -22,6 +49,13 @@ ActiveRecord::Schema.define(:version => 20140223060554) do t.string "name" end + create_table "categories", :force => true do |t| + t.string "name" + t.datetime "created_at" + t.datetime "updated_at" + t.string "parent" + end + create_table "certifications", :force => true do |t| t.string "name" t.string "description" @@ -30,6 +64,19 @@ ActiveRecord::Schema.define(:version => 20140223060554) do t.string "slug" end + create_table "contracts", :force => true do |t| + t.integer "user_id" + t.datetime "first_name" + t.datetime "last_name" + t.datetime "signed_at" + t.string "document_file_name" + t.string "document_content_type" + t.integer "document_file_size" + t.datetime "document_updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "door_logs", :force => true do |t| t.string "key" t.integer "data" @@ -117,6 +164,15 @@ ActiveRecord::Schema.define(:version => 20140223060554) do t.datetime "updated_at", :null => false end + create_table "reservations", :force => true do |t| + t.datetime "checkout_date" + t.string "checkout_signature" + t.datetime "return_date" + t.string "return_signature" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "resource_categories", :force => true do |t| t.string "name" t.datetime "created_at"