Skip to content

Commit

Permalink
Rails: use button_to for deleting feed (#870)
Browse files Browse the repository at this point in the history
This ensures that the authenticity token will be generated and submitted
when deleting a feed.
  • Loading branch information
mockdeep authored Feb 11, 2023
1 parent 00dfa9c commit a8617d5
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 21 deletions.
17 changes: 0 additions & 17 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def update
def destroy
FeedRepository.delete(params[:id])

head(:ok)
flash[:success] = t(".success")
redirect_to("/feeds")
end
end
4 changes: 2 additions & 2 deletions app/views/feeds/_feed.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<span class="edit-feed">
<a class="icon-edit" href="<%= "/feeds/#{feed.id}/edit" %>"></a>
</span>
<span class="remove-feed">
<%= button_to("/feeds/#{feed.id}", method: :delete, class: "remove-feed btn-link") do %>
<a class="icon-remove"></a>
</span>
<% end %>
</div>
</div>
</li>
2 changes: 2 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/el-GR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ el-GR:
index:
add: εισάγεις
add_some_feeds: Επ! Γιατί δεν %{add} μερικά ιστολόγια στη συλλογή σου?
destroy:
success: Η ροή διαγράφηκε.
first_run:
password:
anti_social: αντι-κοινωνικό
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/eo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/he.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ he:
index:
add: להוסיף
add_some_feeds: הי, כדאי %{add} קצת פידים.
destroy:
success: הפיד נמחק.
first_run:
password:
anti_social: אינו חברתי
Expand Down
2 changes: 2 additions & 0 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ ja:
index:
add: 追加
add_some_feeds: 何かフィードを%{add}する必要があります
destroy:
success: フィードを削除しました。
first_run:
password:
anti_social: アンチソーシャル
Expand Down
2 changes: 2 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ ru:
updated_successfully:
index:
add: добавить
add_some_feeds: Эй, ​​Вы должны %{add} некоторые фид каналы.
add_some_feeds: Эй, Вы должны %{add} некоторые фид каналы.
destroy:
success: Фид удален.
first_run:
password:
anti_social: антиобщественное
Expand Down
2 changes: 2 additions & 0 deletions config/locales/sv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ zh-CN:
index:
add: 添加
add_some_feeds: 你应该%{add}一些订阅哟~
destroy:
success: 提要已删除。
first_run:
password:
anti_social: 反社交化的
Expand Down
2 changes: 2 additions & 0 deletions config/locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ zh-TW:
index:
add: 新增
add_some_feeds: 嘿!你應該要%{add}一些訂閱
destroy:
success: 提要已刪除。
first_run:
password:
anti_social: 反社交化的
Expand Down

0 comments on commit a8617d5

Please sign in to comment.