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

前端 未结 5 1235
我寻月下人不归
我寻月下人不归 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:38

    Instead of putting the link of the image in your tag, you can handle it in your controller. And then in your controller you can do something like

    send_file @download.wallpapers[1].wallpaper.url, :type => 'image/jpeg', :disposition => 'attachment'
    

    Read this

提交回复
热议问题