Fixing issue #19 for realsies (oriented by tracking)

This commit is contained in:
Will Bradley 2014-04-10 20:10:04 -07:00
parent 13e72fef23
commit 16c75b2d0f
9 changed files with 28 additions and 5 deletions

View File

@ -18,7 +18,7 @@ class ContractsController < ApplicationController
def create def create
Rails.logger.info "CONTRACT" Rails.logger.info "CONTRACT"
Rails.logger.info @contract.inspect Rails.logger.info @contract.inspect
@contract.created_by = current_user.id @contract.created_by = current_user
respond_to do |format| respond_to do |format|
if @contract.save if @contract.save
format.html { redirect_to @contract, :notice => 'Contract was successfully created.' } format.html { redirect_to @contract, :notice => 'Contract was successfully created.' }

View File

@ -124,6 +124,9 @@ class UsersController < ApplicationController
# POST /users # POST /users
# POST /users.json # POST /users.json
def create def create
# update oriented_by only if orientation has been set
@user.oriented_by_id = current_user.id unless @user.orientation.blank?
respond_to do |format| respond_to do |format|
if @user.save if @user.save
format.html { redirect_to @user, :notice => 'User was successfully created.' } format.html { redirect_to @user, :notice => 'User was successfully created.' }
@ -138,6 +141,10 @@ class UsersController < ApplicationController
# PUT /users/1 # PUT /users/1
# PUT /users/1.json # PUT /users/1.json
def update def update
# update oriented_by only if it's blank but the (new) orientation isn't blank
# gotta test the params because they don't get applied til below.
@user.oriented_by_id = current_user.id if @user.oriented_by.blank? && (!params[:user]["orientation(1i)"].blank?)
respond_to do |format| respond_to do |format|
if @user.update_attributes(params[:user]) if @user.update_attributes(params[:user])
format.html { redirect_to @user, :notice => 'User was successfully updated.' } format.html { redirect_to @user, :notice => 'User was successfully updated.' }

View File

@ -1,5 +1,6 @@
class Contract < ActiveRecord::Base class Contract < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :created_by, :foreign_key => "created_by_id", :class_name => "User"
attr_accessible :user_id, :first_name, :last_name, :cosigner, attr_accessible :user_id, :first_name, :last_name, :cosigner,
:signed_at, :document, :document_file_name, :document_content_type, :signed_at, :document, :document_file_name, :document_content_type,
:document_file_size, :document_updated_at :document_file_size, :document_updated_at

View File

@ -11,6 +11,7 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model # Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :admin, :instructor, :member, :emergency_name, :emergency_phone, :current_skills, :desired_skills, :waiver, :emergency_email, :phone, :payment_method, :orientation, :member_level, :certifications, :hidden, :marketing_source, :payee, :accountant, :exit_reason, :twitter_url, :facebook_url, :github_url, :website_url, :email_visible, :phone_visible, :postal_code #TODO: make admin/instructor/member/etc not accessible attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :admin, :instructor, :member, :emergency_name, :emergency_phone, :current_skills, :desired_skills, :waiver, :emergency_email, :phone, :payment_method, :orientation, :member_level, :certifications, :hidden, :marketing_source, :payee, :accountant, :exit_reason, :twitter_url, :facebook_url, :github_url, :website_url, :email_visible, :phone_visible, :postal_code #TODO: make admin/instructor/member/etc not accessible
belongs_to :oriented_by, :foreign_key => "oriented_by_id", :class_name => "User"
has_many :cards has_many :cards
has_many :user_certifications has_many :user_certifications
has_many :certifications, :through => :user_certifications has_many :certifications, :through => :user_certifications

View File

@ -18,9 +18,14 @@
<%= @contract.signed_at.to_date.to_s(:long) %> <%= @contract.signed_at.to_date.to_s(:long) %>
</small> </small>
</h2> </h2>
<% unless @contract.created_by.blank? %>
<p>
<em>Created by <%= @contract.created_by.name %></em>
</p>
<% end %>
<% if @contract.document.blank? %> <% if @contract.document.blank? %>
No document uploaded <p>No document uploaded</p>
<% else %> <% else %>
<p><%= link_to "Download Contract", @contract.document.url %> <p><%= link_to "Download Contract", @contract.document.url %>
<div class="col-xs-12"> <div class="col-xs-12">

View File

@ -36,6 +36,9 @@
<p> <p>
<b>Orientation?</b> <b>Orientation?</b>
<%= @user.orientation.strftime("%B %d %Y") unless @user.orientation.blank? %> <%= @user.orientation.strftime("%B %d %Y") unless @user.orientation.blank? %>
<% unless @user.oriented_by.blank? %>
<em>(recorded by <%= link_to @user.oriented_by.name, @user.oriented_by %>)</em>
<% end %>
</p> </p>
<p> <p>
<b>Emergency Name:</b> <b>Emergency Name:</b>

View File

@ -1,5 +1,5 @@
class AddCreatedByToContract < ActiveRecord::Migration class AddCreatedByToContract < ActiveRecord::Migration
def change def change
add_column :contracts, :created_by, :integer add_column :contracts, :created_by_id, :integer
end end
end end

View File

@ -0,0 +1,5 @@
class AddOrientedByToUsers < ActiveRecord::Migration
def change
add_column :users, :oriented_by_id, :integer
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140411022819) do ActiveRecord::Schema.define(:version => 20140411024809) do
create_table "cards", :force => true do |t| create_table "cards", :force => true do |t|
t.string "card_number" t.string "card_number"
@ -42,7 +42,7 @@ ActiveRecord::Schema.define(:version => 20140411022819) do
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.string "cosigner" t.string "cosigner"
t.integer "created_by" t.integer "created_by_id"
end end
create_table "door_logs", :force => true do |t| create_table "door_logs", :force => true do |t|
@ -252,6 +252,7 @@ ActiveRecord::Schema.define(:version => 20140411022819) do
t.boolean "email_visible" t.boolean "email_visible"
t.boolean "phone_visible" t.boolean "phone_visible"
t.string "postal_code" t.string "postal_code"
t.integer "oriented_by_id"
end end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true add_index "users", ["email"], :name => "index_users_on_email", :unique => true