Skip to content

Commit d59d7ee

Browse files
committed
s3
1 parent 2902fd8 commit d59d7ee

File tree

18 files changed

+118
-4
lines changed

18 files changed

+118
-4
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414
# Ignore all logfiles and tempfiles.
1515
/log/*.log
1616
/tmp
17+
18+
# Ignore application configuration
19+
/config/application.yml

Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ group :doc do
3232
gem 'sdoc', require: false
3333
end
3434

35+
# After each update, you must "exit" then "bundle install" in Web Dev then "rails server"
36+
#to restart server in SECOND WINDOW
3537
gem "twitter-bootstrap-rails"
3638
gem 'simple_form'
39+
gem 'carrierwave'
40+
gem "fog", "~> 1.3.1"
41+
gem "figaro"
42+
3743

3844

3945

Gemfile.lock

+28
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ GEM
2727
tzinfo (~> 0.3.37)
2828
arel (4.0.2)
2929
builder (3.1.4)
30+
carrierwave (0.10.0)
31+
activemodel (>= 3.2.0)
32+
activesupport (>= 3.2.0)
33+
json (>= 1.7)
34+
mime-types (>= 1.16)
3035
coffee-rails (4.0.1)
3136
coffee-script (>= 2.2.0)
3237
railties (>= 4.0.0, < 5.0)
@@ -35,7 +40,22 @@ GEM
3540
execjs
3641
coffee-script-source (1.7.0)
3742
erubis (2.7.0)
43+
excon (0.13.4)
3844
execjs (2.0.2)
45+
figaro (0.7.0)
46+
bundler (~> 1.0)
47+
rails (>= 3, < 5)
48+
fog (1.3.1)
49+
builder
50+
excon (~> 0.13.0)
51+
formatador (~> 0.2.0)
52+
mime-types
53+
multi_json (~> 1.0)
54+
net-scp (~> 1.0.4)
55+
net-ssh (>= 2.1.3)
56+
nokogiri (~> 1.5.0)
57+
ruby-hmac
58+
formatador (0.2.4)
3959
hike (1.2.3)
4060
i18n (0.6.9)
4161
jbuilder (1.5.3)
@@ -51,6 +71,10 @@ GEM
5171
mime-types (1.25.1)
5272
minitest (4.7.5)
5373
multi_json (1.9.2)
74+
net-scp (1.0.4)
75+
net-ssh (>= 1.99.1)
76+
net-ssh (2.8.0)
77+
nokogiri (1.5.11)
5478
pg (0.17.1)
5579
polyglot (0.3.4)
5680
rack (1.5.2)
@@ -72,6 +96,7 @@ GEM
7296
rake (10.2.2)
7397
rdoc (4.1.1)
7498
json (~> 1.4)
99+
ruby-hmac (0.4.0)
75100
sass (3.2.19)
76101
sass-rails (4.0.3)
77102
railties (>= 4.0.0, < 5.0)
@@ -115,7 +140,10 @@ PLATFORMS
115140
ruby
116141

117142
DEPENDENCIES
143+
carrierwave
118144
coffee-rails (~> 4.0.0)
145+
figaro
146+
fog (~> 1.3.1)
119147
jbuilder (~> 1.2)
120148
jquery-rails
121149
pg

app/assets/images/hurry.jpg

7.5 KB
Loading

app/controllers/posts_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def create
2121
private
2222

2323
def post_params
24-
params.require(:post).permit(:title, :description)
24+
params.require(:post).permit(:title, :description, :image)
2525
end
2626

2727
end

app/models/post.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
class Post < ActiveRecord::Base
2+
mount_uploader :image, PictureUploader
23
end

app/uploaders/picture_uploader.rb

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# encoding: utf-8
2+
3+
class PictureUploader < CarrierWave::Uploader::Base
4+
5+
# Include RMagick or MiniMagick support:
6+
# include CarrierWave::RMagick
7+
# include CarrierWave::MiniMagick
8+
9+
# Choose what kind of storage to use for this uploader:
10+
#storage :file
11+
storage :fog
12+
13+
# Override the directory where uploaded files will be stored.
14+
# This is a sensible default for uploaders that are meant to be mounted:
15+
def store_dir
16+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
17+
end
18+
19+
# Provide a default URL as a default if there hasn't been a file uploaded:
20+
# def default_url
21+
# # For Rails 3.1+ asset pipeline compatibility:
22+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
23+
#
24+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
25+
# end
26+
27+
# Process files as they are uploaded:
28+
# process :scale => [200, 300]
29+
#
30+
# def scale(width, height)
31+
# # do something
32+
# end
33+
34+
# Create different versions of your uploaded files:
35+
# version :thumb do
36+
# process :resize_to_fit => [50, 50]
37+
# end
38+
39+
# Add a white list of extensions which are allowed to be uploaded.
40+
# For images you might use something like this:
41+
# def extension_white_list
42+
# %w(jpg jpeg gif png)
43+
# end
44+
45+
# Override the filename of the uploaded files:
46+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
47+
# def filename
48+
# "something.jpg" if original_filename
49+
# end
50+
51+
end

app/views/posts/index.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
<h1>
66
<%= post.title %>
77
</h1>
8+
9+
10+
<% if post.image.present? %>
11+
<%= image_tag post.image %>
12+
<% end %>
13+
814
<h2>
915

1016
<%= post.description %>

app/views/posts/new.html.erb

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
<br/>
55

66
<%= simple_form_for @post do |f| %>
7-
<%= f.input :title, label: 'Add a title', placeholder: 'Riker, Data, Jordy, Spock, etc.' %>
7+
<%= f.input :title, label: 'What is this?', placeholder: 'Fireworks, bbq steak...' %>
88
<br/>
9-
<%= f.input :description, label: 'What happy?!', placeholder: 'Then we all say "Cool"' %>
9+
<%= f.input :description, label: 'Then we did what?', placeholder: 'We all said, "Cool."' %>
10+
11+
<%= f.input :image %>
12+
1013
<br/>
1114
<%= f.submit 'Save', :class =>
1215
'btn btn-warning' %>

config/initializers/carrierwave.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CarrierWave.configure do |config|
2+
config.fog_credentials = {
3+
:provider => 'AWS', # required
4+
:aws_access_key_id => ENV["AWS_ACCESS_KEY"], # required
5+
:aws_secret_access_key => ENV["AWS_SECRET_KEY"] # required
6+
}
7+
config.fog_directory = ENV["AWS_BUCKET"] # required
8+
9+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AlterPostsAddImage < ActiveRecord::Migration
2+
def change
3+
add_column :posts, :image, :string
4+
5+
end
6+
end

db/schema.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20140412223607) do
14+
ActiveRecord::Schema.define(version: 20140413015744) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
@@ -21,6 +21,7 @@
2121
t.text "description"
2222
t.datetime "created_at"
2323
t.datetime "updated_at"
24+
t.string "image"
2425
end
2526

2627
end

public/uploads/post/image/9/hurry.jpg

7.5 KB
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)