Reputation: 45
I am building a rails app in which a user can upload an mp3 file and then play/delete it. However, I am trying to make it so that when the user pushes the play button, the mp3 file is played without jumping to another page. In my index.html.erb file, I have the following code:
<% @audio.each do |audio| %>
<tr>
<td><%= audio.name %></td>
<td><%= link_to "Play", audio.attachment_url, class: "btn btn-primary" %></td>
I know that I am currently linking my play button to the attachment url, but I don't know how to make it so that it simply plays on the current page. Please help
Upvotes: 0
Views: 176
Reputation: 4649
To answer you question of
make it so that when the user pushes the play button, the mp3 file is played without jumping to another page ... I don't know how to make it so that it simply plays on the current page.
do this ...
$(".btn.btn-primary").on 'click', (event)->
event.preventDefault()
Upvotes: 0
Reputation: 4292
Maybe check out the audio tag? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
Upvotes: 1