Skip to content

Commit

Permalink
Add Paperclip Gem
Browse files Browse the repository at this point in the history
  • Loading branch information
bradley kipp committed Jul 23, 2013
1 parent 6897669 commit 3f20d7e
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 6 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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ gem 'rails', '3.2.13'
gem 'jquery-rails'
gem 'devise'
gem 'simple_form'
gem "paperclip", "~> 3.4.2"

group :production do
gem 'pg'
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ GEM
bootstrap-sass (2.3.2.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.6)
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.14.1)
pg (0.14.1-x86-mingw32)
polyglot (0.3.3)
Expand Down Expand Up @@ -125,6 +135,7 @@ DEPENDENCIES
coffee-rails (~> 3.2.1)
devise
jquery-rails
paperclip (~> 3.4.2)
pg
rails (= 3.2.13)
sass-rails (~> 3.2.3)
Expand Down
9 changes: 7 additions & 2 deletions app/models/pin.rb
Original file line number Diff line number Diff line change
@@ -1,8 +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
validates :user_id, presence: true
has_attached_file :image, styles: { medium: "320x240>" }

end
3 changes: 3 additions & 0 deletions app/views/pins/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +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" } %>

<div class="form-actions">
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/20130723160107_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 => 20130722190751) do
ActiveRecord::Schema.define(:version => 20130723160107) 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 3f20d7e

Please sign in to comment.