Making contracts awesome

This commit is contained in:
2014-04-12 15:05:57 -07:00
parent daeb7713e0
commit 2f4872218e
6 changed files with 129 additions and 10 deletions

View File

@@ -4,6 +4,13 @@ class ContractsController < ApplicationController
layout 'resources'
def index
if params[:user_id].present?
@contracts = Contract.where(user_id: params[:user_id])
end
respond_to do |format|
format.html
format.json { render :json => @contracts }
end
end
def show
@@ -16,8 +23,28 @@ class ContractsController < ApplicationController
end
def create
Rails.logger.info "CONTRACT"
Rails.logger.info @contract.inspect
# if @contract.first_name.blank? && @contract.last_name.blank? && @contract.cosigner.blank? # assume autodetect of filename
# begin
# name_split = params[:contract][:document].original_filename.sub(".jpg","").split
# if name_split.count == 4 # we have one name
# @contract.first_name = name_split[0]
# @contract.last_name = name_split[1]
# # 2 is the hyphen
# @contract.signed_at = Date.parse(name_split[3])
# elsif name_split.count == 7 && name_split[2] == "by" # we have two names
# @contract.first_name = name_split[0]
# @contract.last_name = name_split[1]
# # 2 is "by"
# @contract.cosigner = "#{name_split[3]} #{name_split[4]}"
# # 5 is the hyphen
# @contract.signed_at = Date.parse(name_split[6])
# else
# Rails.logger.info "Couldn't determine name from filename array: #{name_split.inspect}"
# end
# rescue Exception => e
# end
# end
@contract.created_by = current_user
respond_to do |format|
if @contract.save
@@ -30,6 +57,9 @@ class ContractsController < ApplicationController
end
end
def find_for_user
end
def update
respond_to do |format|
if @contract.update_attributes(params[:contract])