我在尝试仅允许用户一次播放一首歌曲时遇到麻烦。当前,如果用户正在收听他们的播放列表,则他们可以推送多首歌曲的播放。我有屏幕截图,并在下面粘贴了代码!
<p id="notice"><%= notice %></p>
<p>
<strong>Title:</strong>
<%= @playlist.title %>
</p>
<p>
<strong>User:</strong>
<%= @playlist.user_id %>
</p>
<%= link_to 'Edit', edit_playlist_path(@playlist) %> |
<%= link_to 'Back', playlists_path %>
<table>
<thead>
<tr>
<th colspan="3">Track Name</th>
<th>Track MP3</th>
</tr>
</thead>
<tbody>
<%if @playlist.tracks.present? %>
<% @playlist.tracks.each do|track|%>
<tr>
<td colspan="3">
<%= track.name%>
</td>
<td>
<%if track.mp3.attached?%>
<audio controls>
<source src="<%= rails_blob_path(track.mp3) %>" type="audio/mpeg">
</audio>
<%end%>
</td>
</tr>
<%end%>
<%end%>
</tbody>
</table>