Rails 'link_to' to Download An Image Immediately Instead of Opening it in the Browser

前端 未结 5 1234
我寻月下人不归
我寻月下人不归 2020-12-31 02:11

I have a link_to Rails helper that downloads a wallpaper when clicked. But the image is loading in the browser instead of being downloaded immediately.

<%         


        
5条回答
  •  醉话见心
    2020-12-31 02:47

    There is an easier way to do this with the HTML5 download attribute.

    <%= link_to 'Download existing avatar', @user.avatar(:original), download: "User_#{@user.id}_avatar" %>
    

提交回复
热议问题