Skip to content

Commit 26276ca

Browse files
committed
Lesson-122/Styling video attach
1 parent 89db33d commit 26276ca

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

app/models/lesson.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ class Lesson < ApplicationRecord
2020
content_type: [ "image/png", "image/jpg", "image/jpeg" ],
2121
size: { less_than: 500.kilobytes, message: "size should be under 500 kilobytes" }
2222

23+
# Sirve para validar que existan thumbnail si hay video
24+
# validates :video_thumbnail, presence: true, if: :video_present?
25+
# def video_present?
26+
# self.video.present?
27+
# end
28+
2329
extend FriendlyId
2430
friendly_id :title, use: :slugged
2531

app/views/lessons/_form.html.haml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
= f.rich_text_area :content
1010
%small= f.error :content, class: "text-danger"
1111
%p
12+
13+
- if @lesson.video.attached?
14+
= @lesson.video.filename
1215
= f.input :video
16+
- if @lesson.video_thumbnail.attached?
17+
-# = image_tag @lesson.video_thumbnail, width: "200px"
18+
-# .row
19+
= @lesson.video_thumbnail.filename
1320
= f.input :video_thumbnail
1421
-# como estaba
1522
-# = f.association :course

app/views/lessons/_lesson.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
= lesson.title
1212
- if policy(lesson).show?
1313
.card-body
14+
-# = image_tag @lesson.video_thumbnail
15+
-if lesson.video.attached? && lesson.video.persisted?
16+
%video(controls="true" poster="#{ url_for lesson.video_thumbnail if lesson.video_thumbnail.attached? }" width="100%" preload="metadata")
17+
%source{src: rails_blob_url(lesson.video), type: "#{lesson.video.content_type}"}
1418
= lesson.content
1519
- if policy(lesson).edit?
1620
.card-footer

app/views/lessons/show.html.haml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
.row
1919
.col-lg-8
2020
= render 'lessons/lesson', lesson: @lesson
21-
= @lesson.video.attached?
22-
= image_tag @lesson.video_thumbnail
23-
%video(controls="true" poster="#{url_for @lesson.video_thumbnail}" width="100%" preload="metadata")
24-
%source{src: rails_blob_url(@lesson.video), type: "#{@lesson.video.content_type}"}
2521
%p
2622
.col-lg-4
2723
%ul.list-group

0 commit comments

Comments
 (0)