Skip to content

Commit 09707fe

Browse files
authored
Merge pull request #73 from dalvarez2596/lesson-115
Added s3 gem
2 parents 6269771 + f4eed95 commit 09707fe

File tree

10 files changed

+44
-11
lines changed

10 files changed

+44
-11
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ gem "groupdate"
8383

8484
gem "rails-erd", group: :development
8585

86+
# aws
87+
gem "aws-sdk-s3", require: false
88+
8689

8790
# row sorting library built for Rails 4.2+. It uses ARel aggressively and is better optimized than most other libraries.
8891
gem "ranked-model"

Gemfile.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ GEM
7676
ast (2.4.2)
7777
autoprefixer-rails (10.4.19.0)
7878
execjs (~> 2)
79+
aws-eventstream (1.3.0)
80+
aws-partitions (1.1029.0)
81+
aws-sdk-core (3.214.1)
82+
aws-eventstream (~> 1, >= 1.3.0)
83+
aws-partitions (~> 1, >= 1.992.0)
84+
aws-sigv4 (~> 1.9)
85+
jmespath (~> 1, >= 1.6.1)
86+
aws-sdk-kms (1.96.0)
87+
aws-sdk-core (~> 3, >= 3.210.0)
88+
aws-sigv4 (~> 1.5)
89+
aws-sdk-s3 (1.176.1)
90+
aws-sdk-core (~> 3, >= 3.210.0)
91+
aws-sdk-kms (~> 1)
92+
aws-sigv4 (~> 1.5)
93+
aws-sigv4 (1.10.1)
94+
aws-eventstream (~> 1, >= 1.0.2)
7995
base64 (0.2.0)
8096
bcrypt (3.1.20)
8197
bigdecimal (3.1.8)
@@ -190,6 +206,7 @@ GEM
190206
jbuilder (2.13.0)
191207
actionview (>= 5.0.0)
192208
activesupport (>= 5.0.0)
209+
jmespath (1.6.2)
193210
json (2.7.2)
194211
language_server-protocol (3.17.0.3)
195212
logger (1.6.1)
@@ -439,6 +456,7 @@ PLATFORMS
439456
x86_64-linux-musl
440457

441458
DEPENDENCIES
459+
aws-sdk-s3
442460
bootsnap
443461
bootstrap (~> 5.3, >= 5.3.3)
444462
brakeman

app/controllers/courses_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,6 @@ def set_course
140140
end
141141

142142
def course_params
143-
params.require(:course).permit(:title, :description, :short_description, :price, :published, :language, :level)
143+
params.require(:course).permit(:title, :description, :short_description, :price, :published, :language, :level, :avatar)
144144
end
145145
end

app/models/course.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class Course < ApplicationRecord
55
belongs_to :user, counter_cache: true
66
# User.find_each{ |user| User.reset_counters(user.id, :courses)}
77

8+
has_one_attached :avatar
9+
810
scope :latest, -> { limit(4).order(created_at: :desc) }
911
scope :top_rated, -> { limit(4).order(average_rating: :desc, created_at: :desc) }
1012
scope :popular, -> { limit(4).order(enrollments_count: :desc, created_at: :desc) }

app/views/courses/_form.html.haml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55

66
.form-inputs
77
= f.input :title
8+
= f.label :avatar
9+
.row
10+
- if @course.avatar.attached?
11+
= image_tag @course.avatar, width: "200px"
12+
.row
13+
= f.file_field :avatar
14+
.row
815
= f.label :description
916
= f.rich_text_area :description
1017
%small= f.error :description, class: "text-danger"

app/views/courses/show.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
%h3
1515
.fa.fa-graduation-cap
1616
= @course.title
17+
.row
18+
-# = @course.avatar.attached?
19+
- if @course.avatar.attached?
20+
= image_tag @course.avatar, width: "200px"
1721
.p-3
1822
.row
1923
.fa.fa-clock

config/credentials.yml.enc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
JB4gb6QALdszymAOXnrywxIWdR40Z+v62qxAj2GJoCBcU9bGqW1QGfBpSSv1tnDejGVGVDyj7m8UPBZIvPybxWPClAjTvv6WcUZpMgU2rhxjNvVXD/7XtXoBeY7pHu0UszOibNpaf7Tj6zWu6ht8y7s9QGFeG8d7vXtJqHsIZ8KmMvdq65pHpAgw0mOipz/F3zDDPethMTyngkTUzjkdQVStOQYmz5S7wtCXimBsPYOwipT4EAZCFnIDo8m+5k9KgkHSBtyo6RGrgBrtc1Fet9kKSPNwrIJGsaRuEElw9co1tucL6MILBBN3+bunXaM90b5QqKpoK2tD+SsnJ4hN0LmCrLUCowUKWsJDXIFqjvoW+wzizKdlc8/JeELjTHj2JXU5ANh/wzRNGV6OnXApTuqo8hUNHKg1Ip+CDKvD1XGMp/xT94LmK9vci9Tu--W9Wog/KInZVuvMx/--WfC3JHxyBw1B4sIaaSunkA==
1+
dLAxa9JqTYQC2V8eCOFBxUieHpiLOuMNDfu/5yu2GLiJz4Ksj946KDgO5Z2d97iTy1uevymkVfBr3Zq/8oeUE08vIqFzeLiEBkn591Gr0yPyi3f6BAVWUb7S8FHjtuYJS8fZzQHnplqex+wwlz+dc2DjBOYDv6YE35A3444j8/4RSg8h7/9wstBA6i/XR67GVMk+GfaUYzOlAtzKvaK3JW9qOG3K0sN86eyJyMG57nVgGkVeARxsqfafL+lfhkI5+ZdefKrZm0o0Twpfbxcv3NbHJUHmK8eFl65JHSB1/69LEQf81jD6ERjv66M0t4fHYqcFuPoUSs0vGzs+cu1ytz2SKxIpmt05XyzVwuGNvHe7Xy/09wBQr79SoIRco1eZpnKLcwdzZYUuWcUAfelHLLnO1MQu92EAibvvRYX+1+C1rqhOhfO3jnk1LUij7KgeykCiA2DudnPoB7mpbuZ/qxRm75CO--6pXS6kpGYNzFySu+--5Hm7lyA2s5hXQ0jYexEOew==

config/environments/development.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
end
3636

3737
# Store uploaded files on the local file system (see config/storage.yml for options).
38-
config.active_storage.service = :local
38+
config.active_storage.service = :amazon
3939

4040
# Don't care if the mailer can't send.
4141
config.action_mailer.raise_delivery_errors = false

config/environments/production.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
3838

3939
# Store uploaded files on the local file system (see config/storage.yml for options).
40-
config.active_storage.service = :local
40+
config.active_storage.service = :amazon
4141

4242
# Mount Action Cable outside main process or domain.
4343
# config.action_cable.mount_path = nil

config/storage.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ local:
77
root: <%= Rails.root.join("storage") %>
88

99
# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10-
# amazon:
11-
# service: S3
12-
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13-
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14-
# region: us-east-1
15-
# bucket: your_own_bucket-<%= Rails.env %>
16-
10+
amazon:
11+
service: S3
12+
access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13+
secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14+
region: us-east-1
15+
bucket: ruby-gems-prod
1716
# Remember not to checkin your GCS keyfile to a repository
1817
# google:
1918
# service: GCS

0 commit comments

Comments
 (0)