Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 05d4dda

Browse files
author
Cassi Gallagher & Jarred Taylor
committed
Add dragonfly files, update user model with dragonfly validations and add migration
1 parent 0a9c288 commit 05d4dda

File tree

7 files changed

+80
-3
lines changed

7 files changed

+80
-3
lines changed

Gemfile

+8
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,11 @@ gem 'ckeditor', github: 'galetahub/ckeditor'
7171
gem 'jquery-rails'
7272

7373
gem 'httparty'
74+
75+
gem 'dragonfly'
76+
77+
gem 'dragonfly-s3_data_store'
78+
79+
group :production do
80+
gem 'rack-cache', require: 'rack/cache'
81+
end

Gemfile.lock

+33
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ GEM
4646
i18n (~> 0.7)
4747
minitest (~> 5.1)
4848
tzinfo (~> 1.1)
49+
addressable (2.5.1)
50+
public_suffix (~> 2.0, >= 2.0.2)
4951
arel (8.0.0)
5052
bcrypt (3.1.11)
5153
bindex (0.5.0)
@@ -69,7 +71,15 @@ GEM
6971
dotenv-rails (2.2.1)
7072
dotenv (= 2.2.1)
7173
railties (>= 3.2, < 5.2)
74+
dragonfly (1.1.3)
75+
addressable (~> 2.3)
76+
multi_json (~> 1.0)
77+
rack (>= 1.3)
78+
dragonfly-s3_data_store (1.3.0)
79+
dragonfly (~> 1.0)
80+
fog-aws
7281
erubi (1.6.1)
82+
excon (0.58.0)
7383
execjs (2.7.0)
7484
factory_girl (4.8.0)
7585
activesupport (>= 3.0.0)
@@ -81,11 +91,28 @@ GEM
8191
faraday (0.12.2)
8292
multipart-post (>= 1.2, < 3)
8393
ffi (1.9.18)
94+
fog-aws (1.4.0)
95+
fog-core (~> 1.38)
96+
fog-json (~> 1.0)
97+
fog-xml (~> 0.1)
98+
ipaddress (~> 0.8)
99+
fog-core (1.45.0)
100+
builder
101+
excon (~> 0.58)
102+
formatador (~> 0.2)
103+
fog-json (1.0.2)
104+
fog-core (~> 1.0)
105+
multi_json (~> 1.10)
106+
fog-xml (0.1.3)
107+
fog-core
108+
nokogiri (>= 1.5.11, < 2.0.0)
109+
formatador (0.2.5)
84110
globalid (0.4.0)
85111
activesupport (>= 4.2.0)
86112
httparty (0.15.6)
87113
multi_xml (>= 0.5.2)
88114
i18n (0.8.6)
115+
ipaddress (0.8.3)
89116
jbuilder (2.7.0)
90117
activesupport (>= 4.2.0)
91118
multi_json (>= 1.2)
@@ -127,8 +154,11 @@ GEM
127154
rack (>= 1.2, < 3)
128155
orm_adapter (0.5.0)
129156
pg (0.21.0)
157+
public_suffix (2.0.5)
130158
puma (3.9.1)
131159
rack (2.0.3)
160+
rack-cache (1.7.0)
161+
rack (>= 0.4)
132162
rack-test (0.6.3)
133163
rack (>= 1.0)
134164
rails (5.1.2)
@@ -240,6 +270,8 @@ DEPENDENCIES
240270
ckeditor!
241271
database_cleaner
242272
dotenv-rails
273+
dragonfly
274+
dragonfly-s3_data_store
243275
factory_girl_rails
244276
faker
245277
httparty
@@ -249,6 +281,7 @@ DEPENDENCIES
249281
neat
250282
pg (~> 0.18)
251283
puma (~> 3.7)
284+
rack-cache
252285
rails (~> 5.1.2)
253286
rails-controller-testing
254287
rspec-rails

app/models/user.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
class User < ApplicationRecord
2-
2+
dragonfly_accessor :image
33
has_many :proposals
44

55
authenticates_with_sorcery!
66
validates :password, presence: true, if: -> { new_record? || changes[:crypted_password] }
77
validates :email, presence: true, uniqueness: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ }
8-
8+
99
validates :password, confirmation: true, if: -> { new_record? || changes[:crypted_password] }
1010
validates :password_confirmation, presence: true, if: -> { new_record? || changes[:crypted_password] }
1111

@@ -20,6 +20,7 @@ class User < ApplicationRecord
2020
validates :website, format: { with: /\A(http:\/\/|https:\/\/)/ , message: "must include http:// or https://" }, allow_blank: true
2121
validates :phone, format: { with: /\A\d{3}-\d{3}-\d{4}\z/ , message: "must be in XXX-XXX-XXXX format"}, allow_blank: true
2222
validates :ein, format: { with: /\A\d{9}\z/, message: "must be 9 digits (without hyphen)"}, allow_blank: true
23+
validates_property :format, of: :image, in: [:jpeg, :jpg, :png, :bmp], case_sensitive: false, message: 'must be .jpeg, .jpg, .png, .bmp format', if: :image_changed?
2324

2425
has_many :projects, foreign_key: :organization_id
2526

config/environments/production.rb

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# Specifies the header that your server uses for sending files.
3939
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
4040
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
41+
config.action_dispatch.rack_cache = true
4142

4243
# Mount Action Cable outside main process or domain
4344
# config.action_cable.mount_path = nil

config/initializers/dragonfly.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'dragonfly'
2+
3+
# Configure
4+
Dragonfly.app.configure do
5+
plugin :imagemagick
6+
7+
secret "1a274426e9406122d568197fa5880708e72efd55b0a650d802981dffbda5c2b3"
8+
9+
url_format "/media/:job/:name"
10+
11+
datastore :file,
12+
root_path: Rails.root.join('public/system/dragonfly', Rails.env),
13+
server_root: Rails.root.join('public')
14+
end
15+
16+
# Logger
17+
Dragonfly.logger = Rails.logger
18+
19+
# Mount as middleware
20+
Rails.application.middleware.use Dragonfly::Middleware
21+
22+
# Add model functionality
23+
if defined?(ActiveRecord::Base)
24+
ActiveRecord::Base.extend Dragonfly::Model
25+
ActiveRecord::Base.extend Dragonfly::Model::Validations
26+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddImageToUsers < ActiveRecord::Migration[5.1]
2+
def change
3+
add_column :users, :image_uid, :string
4+
add_column :users, :image_name, :string
5+
end
6+
end

db/schema.rb

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

13-
ActiveRecord::Schema.define(version: 20170801212436) do
13+
ActiveRecord::Schema.define(version: 20170802185016) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -55,6 +55,8 @@
5555
t.datetime "created_at", null: false
5656
t.datetime "updated_at", null: false
5757
t.string "ein"
58+
t.string "image_uid"
59+
t.string "image_name"
5860
t.index ["email"], name: "index_users_on_email", unique: true
5961
end
6062

0 commit comments

Comments
 (0)