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,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

View File

@@ -1,11 +1,4 @@
module PollsHelper
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
def poll_dates(poll)
if poll.starts_at.blank? || poll.ends_at.blank?
I18n.t("polls.no_dates")

View File

@@ -1,5 +1,5 @@
<div class="small-12 medium-4 large-3">
<%= render "filter" %>
<%= render Admin::Poll::Questions::FilterComponent.new(@polls) %>
</div>
<% if @questions.count == 0 %>