jquery.filedownload , , - , ; . :
A. (front-ent), - , , HTML:
function DownloadFile (id, file_url, _, strTime) {
$.fileDownload(file_url, {
successCallback: function (url) {
$("#ilulModaldow").find('#file_name').html(file_name);
$("#ilulModaldow").find('#file_created_at').html(strTime);
$("#ilulModaldow").modal();
},
failCallback: function (html, url) {
alert('Connection error! Please try again');
}
});
}
B. server side (back-end), I created an action to send the file, this action is the paragraph "file_url" of the javascript function above:
def download
a=APostAttach.find(params[:id])
send_file a.file.path(:original), :type => a.file_content_type
cookies[:fileDownload] = true
cookies[:Path] = "/"
end
C. combine the interface and the end of the font based on the click (file) click event:
$('#attach_<%= attach.id %>').click(function(){
DownloadFile("<%= attach.id %>","<%= download_courses_path(:id => attach.id) %>","<%=attach.file_file_name %>","Uploaded at <%= time_ago_in_words(attach.created_at).gsub('about','') + ' ago'%>");
});
source
share