[英]Store user's email on different page when he/she clicks a button
我想在用户单击某个页面上的(下载)按钮时存储该用户的电子邮件。
这是来自按钮本身的代码:
<div class="my_music_download_2" id="try">
<a class="fas fa-file-download fa-3x" href="<%= my_music.download %>" download></a>
<script>
document.getElementById("try").addEventListener("click", function(){
});
</script>
</div>
我现在不需要在函数中键入什么。
我使用devise进行身份验证。
我的github页面:github.com/Maartensdb/steven-de-baecke/tree/fixes
您可以在会话中存储用户的电子邮件地址,并在其他页面上接收它。
// Store
sessionStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = sessionStorage.getItem("lastname");
假设您的链接处于如下循环中:
<% MyMusic.each.do |my_music| %>
您可以设置视图:
<%= link_to download_path(my_music_id: my_music.id), remote: true do %>
Download
<% end %>
和控制器:
def download
@my_music = MyMusic.find(params[my_music_id])
@my_music.update_attributes(email: current_user.email)
send_data @my_music.download.read, filename: @my_music.download
end
但这会为每个my_music存储最后一次下载它的用户。 如果您想存储谁下载了您需要创建的联接表(如users_downloads)和user_id和my_music_id列,请设置适当的关联。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.