From a8617d551ccd8ca558aa7d0972a3d973b549d004 Mon Sep 17 00:00:00 2001 From: Robert Fletcher Date: Fri, 10 Feb 2023 21:43:01 -0800 Subject: [PATCH] Rails: use button_to for deleting feed (#870) This ensures that the authenticity token will be generated and submitted when deleting a feed. --- app/assets/javascripts/application.js | 17 ----------------- app/controllers/feeds_controller.rb | 3 ++- app/views/feeds/_feed.html.erb | 4 ++-- config/locales/de.yml | 2 ++ config/locales/el-GR.yml | 2 ++ config/locales/en.yml | 2 ++ config/locales/eo.yml | 2 ++ config/locales/es.yml | 2 ++ config/locales/fr.yml | 2 ++ config/locales/he.yml | 2 ++ config/locales/it.yml | 2 ++ config/locales/ja.yml | 2 ++ config/locales/nl.yml | 2 ++ config/locales/pt-BR.yml | 2 ++ config/locales/pt.yml | 2 ++ config/locales/ru.yml | 4 +++- config/locales/sv.yml | 2 ++ config/locales/tr.yml | 2 ++ config/locales/zh-CN.yml | 2 ++ config/locales/zh-TW.yml | 2 ++ 20 files changed, 39 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 7d2c83dfb..ab96d9bf1 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -324,23 +324,6 @@ var AppView = Backbone.View.extend({ }); $(document).ready(function() { - $(".remove-feed").click(function(e) { - e.preventDefault(); - var $this = $(this); - - var feedId = $this.parents("li").data("id"); - - if (feedId > 0) { - $.ajax({url: "/feeds/" + feedId, type: "DELETE"}) - .success(function() { - $this.parents("li").fadeOut(500, function () { - $(this).remove(); - }); - }) - .fail(function() { alert("something broke!"); }); - } - }); - Mousetrap.bind("?", function() { $("#shortcuts").modal('toggle'); }); diff --git a/app/controllers/feeds_controller.rb b/app/controllers/feeds_controller.rb index 7caad171b..4d6e26b4f 100644 --- a/app/controllers/feeds_controller.rb +++ b/app/controllers/feeds_controller.rb @@ -58,6 +58,7 @@ def update def destroy FeedRepository.delete(params[:id]) - head(:ok) + flash[:success] = t(".success") + redirect_to("/feeds") end end diff --git a/app/views/feeds/_feed.html.erb b/app/views/feeds/_feed.html.erb index abe7cd25a..e22470f39 100644 --- a/app/views/feeds/_feed.html.erb +++ b/app/views/feeds/_feed.html.erb @@ -28,9 +28,9 @@ "> - + <%= button_to("/feeds/#{feed.id}", method: :delete, class: "remove-feed btn-link") do %> - + <% end %> diff --git a/config/locales/de.yml b/config/locales/de.yml index 4e8533c62..c2497e154 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -40,6 +40,8 @@ de: index: add: hinzufügen add_some_feeds: Hey, du solltest ein paar Feeds %{add}. + destroy: + success: Feed gelöscht. first_run: password: anti_social: anti-sozial diff --git a/config/locales/el-GR.yml b/config/locales/el-GR.yml index b63b9b66f..67b3491dc 100644 --- a/config/locales/el-GR.yml +++ b/config/locales/el-GR.yml @@ -40,6 +40,8 @@ el-GR: index: add: εισάγεις add_some_feeds: Επ! Γιατί δεν %{add} μερικά ιστολόγια στη συλλογή σου? + destroy: + success: Η ροή διαγράφηκε. first_run: password: anti_social: αντι-κοινωνικό diff --git a/config/locales/en.yml b/config/locales/en.yml index 1baf4c6ab..3ced7bb84 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -41,6 +41,8 @@ en: index: add: add add_some_feeds: Hey, you should %{add} some feeds. + destroy: + success: Feed deleted. first_run: password: anti_social: anti-social diff --git a/config/locales/eo.yml b/config/locales/eo.yml index 2f4450a46..ce37826f9 100644 --- a/config/locales/eo.yml +++ b/config/locales/eo.yml @@ -40,6 +40,8 @@ eo: index: add: aldoni add_some_feeds: He, vi devas %{add} kelkajn fluojn. + destroy: + success: Fluo forigita. first_run: password: anti_social: kontraŭsocia diff --git a/config/locales/es.yml b/config/locales/es.yml index e2cc4d47d..6d9371ba8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -40,6 +40,8 @@ es: index: add: agregar add_some_feeds: Oye, deberias %{add} algunas feeds. + destroy: + success: Feed eliminado. first_run: password: anti_social: anti-social diff --git a/config/locales/fr.yml b/config/locales/fr.yml index d2f895686..b20767fef 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -40,6 +40,8 @@ fr: index: add: ajouter add_some_feeds: Vous devriez %{add} quelques flux. + destroy: + success: Flux supprimé. first_run: password: anti_social: anti-social diff --git a/config/locales/he.yml b/config/locales/he.yml index fd305e498..35462b88f 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -40,6 +40,8 @@ he: index: add: להוסיף add_some_feeds: הי, כדאי %{add} קצת פידים. + destroy: + success: הפיד נמחק. first_run: password: anti_social: אינו חברתי diff --git a/config/locales/it.yml b/config/locales/it.yml index 3ec7da028..550e47bbe 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -40,6 +40,8 @@ it: index: add: aggiungere add_some_feeds: Hey, dovresti %{add} qualche feed. + destroy: + success: Feed eliminato. first_run: password: anti_social: anti-social diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 727e6e769..0e227cf2e 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -40,6 +40,8 @@ ja: index: add: 追加 add_some_feeds: 何かフィードを%{add}する必要があります + destroy: + success: フィードを削除しました。 first_run: password: anti_social: アンチソーシャル diff --git a/config/locales/nl.yml b/config/locales/nl.yml index d10170862..ceb853806 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -40,6 +40,8 @@ nl: index: add: toevoegen add_some_feeds: Hé, je zou eens wat feeds kunnen %{add}. + destroy: + success: Voer verwijderd. first_run: password: anti_social: anti-sociaal diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 21856c4b8..5b04cbdc0 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -40,6 +40,8 @@ pt-BR: index: add: adicionar add_some_feeds: Ei, você deveria %{add} alguns feeds. + destroy: + success: Feed deletado. first_run: password: anti_social: anti-social diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 850f771d9..ae3ad0544 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -40,6 +40,8 @@ pt: index: add: adicionar add_some_feeds: Ei, você deveria %{add} algumas feeds. + destroy: + success: first_run: password: anti_social: anti-social diff --git a/config/locales/ru.yml b/config/locales/ru.yml index ec08c36ba..fb3ad5dbf 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -39,7 +39,9 @@ ru: updated_successfully: index: add: добавить - add_some_feeds: Эй, ​​Вы должны %{add} некоторые фид каналы. + add_some_feeds: Эй, Вы должны %{add} некоторые фид каналы. + destroy: + success: Фид удален. first_run: password: anti_social: антиобщественное diff --git a/config/locales/sv.yml b/config/locales/sv.yml index e7d523dff..d24adef24 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -40,6 +40,8 @@ sv: index: add: lägga till add_some_feeds: Hej, du borde %{add} några feeds. + destroy: + success: Flödet raderat. first_run: password: anti_social: anti-social diff --git a/config/locales/tr.yml b/config/locales/tr.yml index 8b8659b7a..7b5ec359d 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -40,6 +40,8 @@ tr: index: add: ekle add_some_feeds: Hey, you should %{add} some feeds. + destroy: + success: Besleme silindi. first_run: password: anti_social: anti-social diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 9bab436fd..3dda78636 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -40,6 +40,8 @@ zh-CN: index: add: 添加 add_some_feeds: 你应该%{add}一些订阅哟~ + destroy: + success: 提要已删除。 first_run: password: anti_social: 反社交化的 diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 2bc89e9cb..ff9e6a055 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -41,6 +41,8 @@ zh-TW: index: add: 新增 add_some_feeds: 嘿!你應該要%{add}一些訂閱 + destroy: + success: 提要已刪除。 first_run: password: anti_social: 反社交化的