How to create a download link that does not blink?

I would like the user to be able to download the file from the method that I installed in the controller. In addition, I do not want the URL to change in my browser when the user downloads the file. I set this link

<%= link_to image_tag("cc_icon.png"), scenario_download_cc_path(subscription.scenario), target: '_blank' %>

The problem is that a blinking screen appears on the screen when a new tab is created to create a download. It looks visually unattractive. I saw other sites where you click the link, and something starts to load without blinking. How to do it?

Edit: Here is the function called by the link

def download_cc
  scenario = Scenario.find(params[:scenario_id])
  send_data scenario.cc_data, filename: "#{scenario.title}.imscc", type: 'application/zip', :disposition => 'attachment'
end
+4
source share
4

, , Turbolinks - . target: '_blank' data: { turbolinks: false }, Turbolinks . :

<%= link_to image_tag("cc_icon.png"), scenario_download_cc_path(subscription.scenario), data: { turbolinks: false } %>

.

+1

"":

<%= link_to image_tag("cc_icon.png"), scenario_download_cc_path(subscription.scenario), download: true %>
+1

target = "_ blank", , URL- . .

< , : >

HTML CSS ? , css, "" "" "" "" css.

, :

<a href="example.com">My Link</a>

css :

a:visited {
    text-decoration: none;
}

. css, .

CSS Ruby

Ruby : <% = stylesheet_link_tag " " % > css.

: http://www.w3schools.com/css/css_link.asp CSS ruby ​​ rails?

0

While you are using send_file , you should not see the screen blink.

The action scenario_download_cc_path(subscription.scenario)in your controller should look like this:

file_path = File.join(Rails.root, "/public/myfile.whatever")
send_file file_path

The behavior in Chrome and IE looks the same, regardless of whether your link has or not target: '_blank'

0
source

Source: https://habr.com/ru/post/1665182/


All Articles