-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added certificate pdf upload and view
- Loading branch information
1 parent
6f912f3
commit 51403dc
Showing
22 changed files
with
394 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CertificatesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
11 changes: 11 additions & 0 deletions
11
db/migrate/20130826114257_add_attachment_certificate_pdf_to_certificates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.