Adding contracts
This commit is contained in:
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' %>
|
||||
Reference in New Issue
Block a user