Jen Lijó Jen Lijó - 1 year ago 88
Ruby Question

loop through each file using audio_tag Rails 5

I'm new to RoR. I am trying to use audio_tag to reproduce files. My code is reproducing the same song on each audio_tag shown. I would like it to loop through the existed audio files and reproduce them according to its link.

All help will be appreciated!

My code so far:

<% @songs.each do |song| %>
<%= link_to, song.url %>
<%= audio_tag(Song.pluck(:url), controls: true) %>
<%= link_to "Delete >", "songs/delete/?song=" +, :confirm => 'Are you sure you want to delete ' + + '?' %>
<% end %>

Answer Source

Song.pluck(:url) will return an array of the url of every song in your database.

I think you may want:

<?= audio_tag(song.url, controls: true) %>

This will use the url for the current song object.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download