Skip to content

Commit

Permalink
Added certificate pdf upload and view
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcockerham committed Sep 1, 2013
1 parent 6f912f3 commit 51403dc
Show file tree
Hide file tree
Showing 22 changed files with 394 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/assets/javascripts/certificates.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/certificates.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Certificates controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
69 changes: 69 additions & 0 deletions app/assets/stylesheets/scaffolds.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}

a {
color: #000;
&:visited {
color: #666;
}
&:hover {
color: #fff;
background-color: #000;
}
}

div {
&.field, &.actions {
margin-bottom: 10px;
}
}

#notice {
color: green;
}

.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;
}
}
89 changes: 89 additions & 0 deletions app/controllers/certificates_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
class CertificatesController < ApplicationController
# GET /certificates
# GET /certificates.json
def index
@certificates = Certificate.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @certificates }
end
end

# GET /certificates/1
# GET /certificates/1.json
def show
@certificate = Certificate.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @certificate }
end
end

# GET /certificates/new
# GET /certificates/new.json
def new
@certificate = Certificate.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @certificate }
end
end

# GET /certificates/1/edit
def edit
@certificate = Certificate.find(params[:id])
end

# POST /certificates
# POST /certificates.json
def create
@certificate = Certificate.new(params[:certificate])

respond_to do |format|
if @certificate.save
format.html { redirect_to @certificate, notice: 'Certificate was successfully created.' }
format.json { render json: @certificate, status: :created, location: @certificate }
else
format.html { render action: "new" }
format.json { render json: @certificate.errors, status: :unprocessable_entity }
end
end
end

# PUT /certificates/1
# PUT /certificates/1.json
def update
@certificate = Certificate.find(params[:id])

respond_to do |format|
if @certificate.update_attributes(params[:certificate])
format.html { redirect_to @certificate, notice: 'Certificate was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @certificate.errors, status: :unprocessable_entity }
end
end
end

# DELETE /certificates/1
# DELETE /certificates/1.json
def destroy
@certificate = Certificate.find(params[:id])
@certificate.destroy

respond_to do |format|
format.html { redirect_to certificates_url }
format.json { head :no_content }
end
end

# def pdf
# pdf_filename = File.join(Rails.root, "/system/certificates/certificate_pdfs/000/000/007/thumb/19035122-V2W-LFCZ_(1).pdf")
# send_file(pdf_filename, :filename => "19035122-V2W-LFCZ_(1).pdf", :disposition => 'inline', :type => "application/pdf")

#end
end
2 changes: 2 additions & 0 deletions app/helpers/certificates_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CertificatesHelper
end
11 changes: 11 additions & 0 deletions app/models/certificate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Certificate < ActiveRecord::Base
attr_accessible :date_completed, :institution, :name, :certificate_pdf, :user_id

validates :institution, presence: true
validates :user_id, presence: true
validates_attachment :certificate_pdf, presence: true,
content_type: { content_type: "application/pdf" },
size: { less_than: 10.megabytes }
belongs_to :user
has_attached_file :certificate_pdf #, :styles => { :thumb => ["50x50#", :png] }
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class User < ActiveRecord::Base
has_many :job_applications, :dependent => :destroy
has_many :job_experiences, :dependent => :destroy

has_many :certificates

# Nested Attributes
accepts_nested_attributes_for :job_experiences
# :allow_destroy => true,
Expand Down
19 changes: 19 additions & 0 deletions app/views/certificates/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%= simple_form_for(@certificate) do |f| %>
<%= f.error_notification %>
<%= f.full_error :certificate_pdf_content_type, class: "alert alert-error" %>
<%= f.full_error :certificate_pdf_file_size, class: "alert alert-error" %>

<div class="form-inputs">
<%= f.input :name %>
<%= f.input :institution %>
<%= f.input :date_completed %>
<%= f.input :certificate_pdf, label: "Upload a pdf of your certificate" %>
</div>
<div>
<%= f.hidden_field :user_id, value: current_user.id %>
</div>

<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/certificates/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing certificate</h1>

<%= render 'form' %>

<%= link_to 'Show', @certificate %> |
<%= link_to 'Back', certificates_path %>
27 changes: 27 additions & 0 deletions app/views/certificates/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h1>Listing certificates</h1>

<table>
<tr>
<th>Name</th>
<th>Institution</th>
<th>Date completed</th>
<th></th>
<th></th>
<th></th>
</tr>

<% @certificates.each do |certificate| %>
<tr>
<td><%= certificate.name %></td>
<td><%= certificate.institution %></td>
<td><%= certificate.date_completed %></td>
<td><%= link_to 'Show', certificate %></td>
<td><%= link_to 'Edit', edit_certificate_path(certificate) %></td>
<td><%= link_to 'Destroy', certificate, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New Certificate', new_certificate_path %>
5 changes: 5 additions & 0 deletions app/views/certificates/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New certificate</h1>

<%= render 'form' %>

<%= link_to 'Back', certificates_path %>
35 changes: 35 additions & 0 deletions app/views/certificates/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<p id="notice"><%= notice %></p>

<div class="row">
<div class="span6 offset3">
<div class="well">

<embed src=<%= @certificate.certificate_pdf %> width="500" height="375" type="application/pdf">
<iframe src=<%= @certificate.certificate_pdf %> width="600" height="780" style="border: none;"> </iframe>

<%= link_to "View Certificate" , @certificate.certificate_pdf.url %>
<!--<iframe src="http://docs.google.com/viewer?url=http%3A%2F%2Ff.cl.ly%2Fitems%2F0E1l1h1W2W3J423w1q1X%2Ftest.pdf&embedded=true" width="600" height="780" style="border: none;"></iframe>
@certificate.certificate_pdf.url
<embed src="@certificate.certificate_pdf.path" width="500" height="375" type="application/pdf">
<embed src="/system/certificates/certificate_pdfs/000/000/007/19035122-V2W-LFCZ_(1).pdf" width="500" height="375" type="application/pdf">
-->
<p>
<b>Name:</b>
</p>

<p>
<b>Institution:</b>
<%= @certificate.institution %>
</p>

<p>
<b>Date completed:</b>
<%= @certificate.date_completed %>
</p>

<%= link_to 'Edit', edit_certificate_path(@certificate) %> |
<%= link_to 'Back', certificates_path %>

</div>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</ul>
<ul class='nav pull-right'>
<% if user_signed_in? %>
<li><%= link_to "Add Certificate", new_certificate_path %></li>
<li><%= link_to "Add +", new_pin_path %></li>
<li><%= link_to "Edit Profile", edit_user_registration_path %></li>
<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Omrails::Application.routes.draw do

resources :certificates


resources :job_experiences


Expand Down Expand Up @@ -34,6 +37,8 @@

get 'job_posting_applications' => 'job_postings#show_applications'

match '/certificates/pdf/:id' => 'certificates#pdf'

# The priority is based upon order of creation:
# first created -> highest priority.

Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20130825215632_create_certificates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateCertificates < ActiveRecord::Migration
def change
create_table :certificates do |t|
t.string :name
t.string :institution
t.date :date_completed

t.timestamps
end
add_index :certificates, :institution
end
end
6 changes: 6 additions & 0 deletions db/migrate/20130825220821_add_user_id_to_certificates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddUserIdToCertificates < ActiveRecord::Migration
def change
add_column :certificates, :user_id, :integer
add_index :certificates, :user_id
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddAttachmentCertificatePdfToCertificates < ActiveRecord::Migration
def self.up
change_table :certificates do |t|
t.attachment :certificate_pdf
end
end

def self.down
drop_attached_file :certificates, :certificate_pdf
end
end
18 changes: 17 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130707184331) do
ActiveRecord::Schema.define(:version => 20130826114257) do

create_table "applications", :force => true do |t|
t.integer "job_id"
Expand All @@ -21,6 +21,22 @@

add_index "applications", ["job_id"], :name => "index_applications_on_job_id"

create_table "certificates", :force => true do |t|
t.string "name"
t.string "institution"
t.date "date_completed"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
t.string "certificate_pdf_file_name"
t.string "certificate_pdf_content_type"
t.integer "certificate_pdf_file_size"
t.datetime "certificate_pdf_updated_at"
end

add_index "certificates", ["institution"], :name => "index_certificates_on_institution"
add_index "certificates", ["user_id"], :name => "index_certificates_on_user_id"

create_table "job_applications", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/certificates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
name: MyString
institution: MyString
date_completed: 2013-08-25

two:
name: MyString
institution: MyString
date_completed: 2013-08-25
Loading

0 comments on commit 51403dc

Please sign in to comment.