Skip to content

Added s3 gem #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@
# group date
gem "groupdate"

# generation of erd

Check failure on line 82 in Gemfile

View workflow job for this annotation

GitHub Actions / lint

Layout/TrailingWhitespace: Trailing whitespace detected.

gem "rails-erd", group: :development

# aws
gem "aws-sdk-s3", require: false


# row sorting library built for Rails 4.2+. It uses ARel aggressively and is better optimized than most other libraries.
gem "ranked-model"
Expand Down
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ GEM
ast (2.4.2)
autoprefixer-rails (10.4.19.0)
execjs (~> 2)
aws-eventstream (1.3.0)
aws-partitions (1.1029.0)
aws-sdk-core (3.214.1)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.96.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.176.1)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
aws-sigv4 (1.10.1)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.8)
Expand Down Expand Up @@ -190,6 +206,7 @@ GEM
jbuilder (2.13.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jmespath (1.6.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
logger (1.6.1)
Expand Down Expand Up @@ -439,6 +456,7 @@ PLATFORMS
x86_64-linux-musl

DEPENDENCIES
aws-sdk-s3
bootsnap
bootstrap (~> 5.3, >= 5.3.3)
brakeman
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ def set_course
end

def course_params
params.require(:course).permit(:title, :description, :short_description, :price, :published, :language, :level)
params.require(:course).permit(:title, :description, :short_description, :price, :published, :language, :level, :avatar)
end
end
2 changes: 2 additions & 0 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
belongs_to :user, counter_cache: true
# User.find_each{ |user| User.reset_counters(user.id, :courses)}

has_one_attached :avatar

scope :latest, -> { limit(4).order(created_at: :desc) }
scope :top_rated, -> { limit(4).order(average_rating: :desc, created_at: :desc) }
scope :popular, -> { limit(4).order(enrollments_count: :desc, created_at: :desc) }
scope :published, -> { where(published: true) }
scope :unpublished, -> {where(published: false) }

Check failure on line 14 in app/models/course.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideBlockBraces: Space missing inside {.
scope :approved, -> { where(approved: true) }
scope :unapproved, -> { where(approved: false) }

Expand Down
7 changes: 7 additions & 0 deletions app/views/courses/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

.form-inputs
= f.input :title
= f.label :avatar
.row
- if @course.avatar.attached?
= image_tag @course.avatar, width: "200px"
.row
= f.file_field :avatar
.row
= f.label :description
= f.rich_text_area :description
%small= f.error :description, class: "text-danger"
Expand Down
4 changes: 4 additions & 0 deletions app/views/courses/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
%h3
.fa.fa-graduation-cap
= @course.title
.row
-# = @course.avatar.attached?
- if @course.avatar.attached?
= image_tag @course.avatar, width: "200px"
.p-3
.row
.fa.fa-clock
Expand Down
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
JB4gb6QALdszymAOXnrywxIWdR40Z+v62qxAj2GJoCBcU9bGqW1QGfBpSSv1tnDejGVGVDyj7m8UPBZIvPybxWPClAjTvv6WcUZpMgU2rhxjNvVXD/7XtXoBeY7pHu0UszOibNpaf7Tj6zWu6ht8y7s9QGFeG8d7vXtJqHsIZ8KmMvdq65pHpAgw0mOipz/F3zDDPethMTyngkTUzjkdQVStOQYmz5S7wtCXimBsPYOwipT4EAZCFnIDo8m+5k9KgkHSBtyo6RGrgBrtc1Fet9kKSPNwrIJGsaRuEElw9co1tucL6MILBBN3+bunXaM90b5QqKpoK2tD+SsnJ4hN0LmCrLUCowUKWsJDXIFqjvoW+wzizKdlc8/JeELjTHj2JXU5ANh/wzRNGV6OnXApTuqo8hUNHKg1Ip+CDKvD1XGMp/xT94LmK9vci9Tu--W9Wog/KInZVuvMx/--WfC3JHxyBw1B4sIaaSunkA==
dLAxa9JqTYQC2V8eCOFBxUieHpiLOuMNDfu/5yu2GLiJz4Ksj946KDgO5Z2d97iTy1uevymkVfBr3Zq/8oeUE08vIqFzeLiEBkn591Gr0yPyi3f6BAVWUb7S8FHjtuYJS8fZzQHnplqex+wwlz+dc2DjBOYDv6YE35A3444j8/4RSg8h7/9wstBA6i/XR67GVMk+GfaUYzOlAtzKvaK3JW9qOG3K0sN86eyJyMG57nVgGkVeARxsqfafL+lfhkI5+ZdefKrZm0o0Twpfbxcv3NbHJUHmK8eFl65JHSB1/69LEQf81jD6ERjv66M0t4fHYqcFuPoUSs0vGzs+cu1ytz2SKxIpmt05XyzVwuGNvHe7Xy/09wBQr79SoIRco1eZpnKLcwdzZYUuWcUAfelHLLnO1MQu92EAibvvRYX+1+C1rqhOhfO3jnk1LUij7KgeykCiA2DudnPoB7mpbuZ/qxRm75CO--6pXS6kpGYNzFySu+--5Hm7lyA2s5hXQ0jYexEOew==
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
end

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

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX

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

# Mount Action Cable outside main process or domain.
# config.action_cable.mount_path = nil
Expand Down
13 changes: 6 additions & 7 deletions config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ local:
root: <%= Rails.root.join("storage") %>

# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
# region: us-east-1
# bucket: your_own_bucket-<%= Rails.env %>

amazon:
service: S3
access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
region: us-east-1
bucket: ruby-gems-prod
# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
Expand Down
Loading