Skip to content

Commit

Permalink
add audio attach
Browse files Browse the repository at this point in the history
  • Loading branch information
o-200 committed Dec 18, 2024
1 parent 7cd72e7 commit 7ff5810
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/podcasts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def destroy
private

def podcast_params
params.require(:podcast).permit(:title, :description, :user_id, :photo)
params.require(:podcast).permit(:title, :description, :user_id, :photo, :audio)
end
end
1 change: 1 addition & 0 deletions app/models/podcast.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class Podcast < ApplicationRecord
has_one_attached :photo
has_one_attached :audio
end
22 changes: 22 additions & 0 deletions app/views/podcasts/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
<%= form.text_area :description, class: "form-control" %>
</div>

<div data-controller="upload">
<%= form.label :photo, "Обложка" %>
<%= form.file_field :photo, direct_upload: true,
data: { upload_target: "input",
action: "change->upload#uploadFile" }
%>
<div data-upload-target="progress" style="width: 100%; background-color: #f3f3f3; border: 1px solid #ccc; height: 20px; position: relative;">
<div id="progress-bar" style="width: 0%; height: 100%; background-color: #4caf50; position: absolute; transition: width 0.2s;"></div>
</div>
</div>

<div data-controller="upload">
<%= form.label :audio, "Аудиофайл" %>
<%= form.file_field :audio, direct_upload: true,
data: { upload_target: "input",
action: "change->upload#uploadFile" }
%>
<div data-upload-target="progress" style="width: 100%; background-color: #f3f3f3; border: 1px solid #ccc; height: 20px; position: relative;">
<div id="progress-bar" style="width: 0%; height: 100%; background-color: #4caf50; position: absolute; transition: width 0.2s;"></div>
</div>
</div>

<%= form.submit "Сохранить изменения", class: "btn btn-primary" %>
<% end %>

Expand Down
12 changes: 12 additions & 0 deletions app/views/podcasts/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</div>

<div data-controller="upload">
<%= form.label :photo, "Обложка" %>
<%= form.file_field :photo, direct_upload: true,
data: { upload_target: "input",
action: "change->upload#uploadFile" }
Expand All @@ -21,6 +22,17 @@
</div>
</div>

<div data-controller="upload">
<%= form.label :audio, "Аудиофайл" %>
<%= form.file_field :audio, direct_upload: true,
data: { upload_target: "input",
action: "change->upload#uploadFile" }
%>
<div data-upload-target="progress" style="width: 100%; background-color: #f3f3f3; border: 1px solid #ccc; height: 20px; position: relative;">
<div id="progress-bar" style="width: 0%; height: 100%; background-color: #4caf50; position: absolute; transition: width 0.2s;"></div>
</div>
</div>

<%= form.submit "Создать Podcast", class: "btn btn-primary" %>
<% end %>
</div>
13 changes: 7 additions & 6 deletions app/views/podcasts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
<div class="alert alert-warning" role="alert">No Photo Available!</div>
<% end %>

<audio controls class="mb-3">
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

<% if @podcast.audio.attached? %>
<%= audio_tag @podcast.audio, controls: true %>
<% else %>
<div class="alert alert-warning" role="alert">No Audio Available!</div>
<% end %>
</div>
<div class="d-flex flex-column mb-3">
<%= link_to "Редактировать Podcast", edit_podcast_path(@podcast), class: "btn btn-secondary mb-2" %>
<%= link_to "Удалить Podcast", podcast_path(@podcast), method: :delete, data: { confirm: "Вы уверены?" }, class: "btn btn-danger mb-2" %>
</div>
Expand Down

0 comments on commit 7ff5810

Please sign in to comment.