Adding contracts
This commit is contained in:
parent
095b6d3965
commit
c74da562bc
50
app/controllers/contracts_controller.rb
Normal file
50
app/controllers/contracts_controller.rb
Normal file
|
@ -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
|
12
app/models/contract.rb
Normal file
12
app/models/contract.rb
Normal file
|
@ -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
|
36
app/views/contracts/_form.html.erb
Normal file
36
app/views/contracts/_form.html.erb
Normal file
|
@ -0,0 +1,36 @@
|
|||
<%= form_for(@contract, html: {class: "col-sm-6"}) do |f| %>
|
||||
<% if @contract.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(@contract.errors.count, "error") %> prohibited this contract from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% @contract.errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= f.label :first_name %><br />
|
||||
<%= f.text_field :first_name, class: "form-control" %>
|
||||
</p>
|
||||
<p>
|
||||
<%= f.label :last_name %><br />
|
||||
<%= f.text_field :last_name, class: "form-control" %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :signed_at %><br />
|
||||
<%= f.date_select :signed_at, class: "form-control" %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :document %><br />
|
||||
<%= f.file_field :document %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.submit nil, class: "btn btn-primary" %>
|
||||
</p>
|
||||
<% end %>
|
21
app/views/contracts/index.html.erb
Normal file
21
app/views/contracts/index.html.erb
Normal file
|
@ -0,0 +1,21 @@
|
|||
<div class="row">
|
||||
<h1 class="col-md-8">Contracts
|
||||
<%= link_to 'Add Contract', new_contract_path, :class => "btn btn-success" if can? :create, Contract %>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<% @contracts.sort_by{|r| [r.last_name] }.each do |contract| %>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<%= contract.last_name %>
|
||||
<%= contract.first_name %>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
|
4
app/views/contracts/new.html.erb
Normal file
4
app/views/contracts/new.html.erb
Normal file
|
@ -0,0 +1,4 @@
|
|||
<h1>New Contract
|
||||
<%= link_to 'Back', contracts_path, class: "btn btn-default" %>
|
||||
</h1>
|
||||
<%= render 'form' %>
|
|
@ -19,6 +19,8 @@ Dooraccess::Application.routes.draw do
|
|||
|
||||
resources :certifications
|
||||
|
||||
resources :contracts
|
||||
|
||||
devise_for :users, :skip => :registrations
|
||||
devise_scope :user do
|
||||
resource :registration,
|
||||
|
|
16
db/migrate/20140227095847_create_contracts.rb
Normal file
16
db/migrate/20140227095847_create_contracts.rb
Normal file
|
@ -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
|
58
db/schema.rb
58
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"
|
||||
|
|
Loading…
Reference in New Issue
Block a user