Skip to content

Commit 0b2d9aa

Browse files
committed
#5 Check if destroy method comes by AJAX
1 parent db7e8ba commit 0b2d9aa

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

app/controllers/kebapage/media_controller.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ def create
1616
def destroy
1717
@medium = Medium.find(params[:id])
1818
@medium.destroy
19-
render nothing: true
19+
20+
if request.xhr?
21+
render nothing: true
22+
else
23+
redirect_to media_path
24+
end
25+
2026
end
2127
end
2228
end

app/views/kebapage/media/index.html.haml

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@
3636
= media.attachment_updated_at.to_date
3737
%td.action
3838
%a.btn.btn-success{href: media.attachment.url }
39-
%i.icon-zoom-in
39+
%i.icon-zoom-in
40+
= link_to medium_path(media), method: :delete, data: { confirm: I18n.t('kebapage.ru_sure') }, class: 'btn btn-danger' do
41+
%i.icon-trash

0 commit comments

Comments
 (0)