当他们在我的应用程序中单击下载时,我正在向客户端发送文件,但是,客户端没有下载文件,但控制台指示文件已发送。
显示.html.erb
<div class="col-10 music-detail">
<hr/>
<%= form_for :music, url: music_download_path do |f| %>
<%= f.hidden_field :music_id, value: @music.id %>
<%= f.submit :download, class:"download_btn "%>
<span class="sownload_count"><%= @music.download_count%></span>
<% end %>
</div>
音乐控制器.rb
def download
music_id = params[:music][:music_id]
music = Music.find(music_id)
if music.valid?
music_rel_path = music.music_path
music_file = gen_absolute_file_path music_rel_path
send_file(music_file)
download_count = music.download_count + 1
music.update(download_count: download_count)
redirect_to "/musics/#{music_id}"
end
end
rails 服务器控制台输出指示文件已发送
Started POST "/music_download" for 127.0.0.1 at 2018-09-19 08:30:31 -0700
Processing by MusicsController#download as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"JmeNUnm7HgW8T55fALqQxN9a2v9MDKmJZCWsQ0MYfu3t1ETteowbAL UMB0bf9Tu0zxFFORNj2TmOgnWW8EARIQ==", "music"=>{"music_id"=>"2"}, "commit"=>"download"}
Music Load (0.0ms) SELECT "musics".* FROM "musics" WHERE "musics"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
Sent file C:/Users/USER/Desktop/projects/filmz_legendary/public/secure/musics/samuel_samuel-samuel/all_of_my_days.mp3 (48.5ms)
(0.0ms) begin transaction SQL (3.0ms) UPDATE "musics" SET "download_count" = ?, "updated_at" = ? WHERE "musics"."id" = ? [["download_count", 7], ["updated_at", "2018-09-19 15:30:32.789257"], ["id", 2]]
(202.7ms) commit transaction
Redirected to http://localhost:3000/musics/2
Completed 302 Found in 274ms (ActiveRecord: 205.7ms)
Started GET "/musics/2" for 127.0.0.1 at 2018-09-19 08:30:33 -0700
Processing by MusicsController#show as HTML
Parameters: {"id"=>"2"}
Music Load (0.0ms) SELECT "musics".* FROM "musics" WHERE "musics"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
Rendering musics/show.html.erb within layouts/application
Rendered musics/show.html.erb within layouts/application (5.0ms)
Rendered layouts/_header.html.erb (1.0ms)
Rendered layouts/_footer.html.erb (1.0ms)
Completed 200 OK in 5278ms (Views: 5087.8ms | ActiveRecord: 0.0ms)
我在用 :
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
ralis 5.1.6