Extract poll questions filter to a component
This commit is contained in:
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
|
||||
@@ -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")
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
Reference in New Issue
Block a user