Extract component to mark a debate as featured
We're also moving the path argument in the `link_to` calls to a different line, since it's what we usually do.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
|
|
||||
<% if debate.featured? %>
|
||||
<%= link_to t("admin.actions.unmark_featured").capitalize,
|
||||
unmark_featured_debate_path(debate),
|
||||
method: :put,
|
||||
data: { confirm: t("admin.actions.confirm_action",
|
||||
action: t("admin.actions.unmark_featured"),
|
||||
name: debate.title) } %>
|
||||
<% else %>
|
||||
<%= link_to t("admin.actions.mark_featured").capitalize,
|
||||
mark_featured_debate_path(debate),
|
||||
method: :put,
|
||||
data: { confirm: t("admin.actions.confirm_action",
|
||||
action: t("admin.actions.mark_featured"),
|
||||
name: debate.title) } %>
|
||||
<% end %>
|
||||
12
app/components/debates/mark_featured_action_component.rb
Normal file
12
app/components/debates/mark_featured_action_component.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class Debates::MarkFeaturedActionComponent < ApplicationComponent
|
||||
attr_reader :debate
|
||||
use_helpers :can?
|
||||
|
||||
def initialize(debate)
|
||||
@debate = debate
|
||||
end
|
||||
|
||||
def render
|
||||
can? :mark_featured, debate
|
||||
end
|
||||
end
|
||||
@@ -1,18 +1,2 @@
|
||||
<%= render Shared::ModerationActionsComponent.new(debate) %>
|
||||
|
||||
<% if can? :mark_featured, debate %>
|
||||
|
|
||||
<% if debate.featured? %>
|
||||
<%= link_to t("admin.actions.unmark_featured").capitalize, unmark_featured_debate_path(debate),
|
||||
method: :put,
|
||||
data: { confirm: t("admin.actions.confirm_action",
|
||||
action: t("admin.actions.unmark_featured"),
|
||||
name: debate.title) } %>
|
||||
<% else %>
|
||||
<%= link_to t("admin.actions.mark_featured").capitalize, mark_featured_debate_path(debate),
|
||||
method: :put,
|
||||
data: { confirm: t("admin.actions.confirm_action",
|
||||
action: t("admin.actions.mark_featured"),
|
||||
name: debate.title) } %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= render Debates::MarkFeaturedActionComponent.new(debate) %>
|
||||
|
||||
Reference in New Issue
Block a user