# source https://stackoverflow.com/questions/16242359/how-to-trigger-download-with-rails-send-data-from-ajax-post#17526267
create a function in controller
def ajax_download
send_file "path_to_file/" + params[:file]
end
and then in controller action
respond_to do |format|
@java_url = "/home/ajax_download?file=#{file_name}"
format.js {render :partial => "downloadFile"}
end
and make a partial in view folder name with _downloadFile.js.erb and write this line
window.location.href = "<%=@java_url %>"