Extract poll questions filter to a component

This commit is contained in:
Javi Martín
2021-06-28 04:26:03 +02:00
parent ccbc708b5b
commit 422404085f
4 changed files with 18 additions and 8 deletions

View File

@@ -0,0 +1,7 @@
<%= form_tag "", method: :get do %>
<%= label_tag :poll_id, t("admin.questions.index.filter_poll") %>
<%= select_tag "poll_id",
poll_select_options,
prompt: t("polls.all"),
class: "js-location-changer" %>
<% end %>

View File

@@ -0,0 +1,17 @@
class Admin::Poll::Questions::FilterComponent < ApplicationComponent
attr_reader :polls
delegate :current_path_with_query_params, to: :helpers
def initialize(polls)
@polls = polls
end
private
def poll_select_options
options = polls.map do |poll|
[poll.name, current_path_with_query_params(poll_id: poll.id)]
end
options_for_select(options, request.fullpath)
end
end