Skip to content

Commit

Permalink
added Paperclip Gem
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcockerham committed Jun 4, 2013
1 parent 147f1dd commit acd606e
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ doc/
*~
.project
.DS_Store
.idea
.idea

# Ignore Paperclip uploaded files
/public/system
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ gem 'rails', '3.2.12'
gem 'jquery-rails'
gem 'devise'
gem 'simple_form'
gem "paperclip", "~> 3.0"

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
Expand All @@ -14,7 +15,6 @@ end

group :development, :test do
gem 'sqlite3'
gem 'webrick', '~> 1.3.1'
end

# Gems used only for assets and not required
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ GEM
bootstrap-sass (2.3.1.0)
sass (~> 3.2)
builder (3.0.4)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.1)
climate_control (>= 0.0.3, < 1.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
Expand Down Expand Up @@ -62,6 +66,12 @@ GEM
mime-types (1.23)
multi_json (1.7.2)
orm_adapter (0.4.0)
paperclip (3.4.2)
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
activesupport (>= 3.0.0)
cocaine (~> 0.5.0)
mime-types
pg (0.15.1)
polyglot (0.3.3)
rack (1.4.5)
Expand Down Expand Up @@ -123,6 +133,7 @@ DEPENDENCIES
coffee-rails (~> 3.2.1)
devise
jquery-rails
paperclip (~> 3.0)
pg
rails (= 3.2.12)
sass-rails (~> 3.2.3)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def answer
def vip
end

def new_job_post
def job_post
end
end
8 changes: 6 additions & 2 deletions app/models/pin.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
class Pin < ActiveRecord::Base
attr_accessible :description
attr_accessible :description, :image

validates :description, presence: true
validates :user_id, presence: true
validates_attachment :image, presence: true,
content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] },
size: { less_than: 5.megabytes }

belongs_to :user
has_attached_file :image, styles: { medium: "320x240>" }

validates :user_id, presence: true
end
4 changes: 3 additions & 1 deletion app/views/pins/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<%= simple_form_for(@pin, html: { class: "form-horizontal"}) do |f| %>
<%= f.error_notification %>
<%= f.full_error :image_file_size, class: "alert alert-error" %>
<%= f.full_error :image_content_type, class: "alert alert-error" %>


<%= f.input :image, label: "Upload an image" %>
<%= f.input :description, as: :text, input_html: { rows: "3" } %>


Expand Down
1 change: 1 addition & 0 deletions app/views/pins/_pin.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<tr>
<td><%= image_tag pin.image(:medium) %></td>
<td><%= pin.description %></td>
<td><%= link_to 'Show', pin %></td>
<% if current_user == pin.user %>
Expand Down
1 change: 1 addition & 0 deletions app/views/pins/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<table class="table table-striped">
<thead>
<tr>
<th>Image</th>
<th>Description</th>
<th></th>
<th></th>
Expand Down
1 change: 1 addition & 0 deletions app/views/pins/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="row">
<div class="span6 offset3">
<div class="well">
<%= image_tag @pin.image %>
<p>
<%= @pin.description %>
</p>
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20130604110107_add_attachment_image_to_pins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddAttachmentImageToPins < ActiveRecord::Migration
def self.up
change_table :pins do |t|
t.attachment :image
end
end

def self.down
drop_attached_file :pins, :image
end
end
10 changes: 7 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130602172033) do
ActiveRecord::Schema.define(:version => 20130604110107) do

create_table "pins", :force => true do |t|
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end

add_index "pins", ["user_id"], :name => "index_pins_on_user_id"
Expand Down

0 comments on commit acd606e

Please sign in to comment.