Я отправляю файл клиенту, когда они нажимают на кнопку «загрузить» в моем приложении, однако файл не загружается клиентом, но консоль указывает, что файл был отправлен.
show.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>
MusicController.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