Extract poll questions filter to a component
This commit is contained in:
@@ -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 %>
|
||||
17
app/components/admin/poll/questions/filter_component.rb
Normal file
17
app/components/admin/poll/questions/filter_component.rb
Normal 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
|
||||
Reference in New Issue
Block a user