From 7efd7c89ef68e984cf890dfd23552d85877af66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= <15726+Senen@users.noreply.github.com> Date: Wed, 31 Aug 2022 17:28:33 +0200 Subject: [PATCH] Extract `Polls::QuestionComponent` --- .../polls/questions/question_component.html.erb} | 0 app/components/polls/questions/question_component.rb | 7 +++++++ app/views/polls/show.html.erb | 4 +--- 3 files changed, 8 insertions(+), 3 deletions(-) rename app/{views/polls/questions/_question.html.erb => components/polls/questions/question_component.html.erb} (100%) create mode 100644 app/components/polls/questions/question_component.rb diff --git a/app/views/polls/questions/_question.html.erb b/app/components/polls/questions/question_component.html.erb similarity index 100% rename from app/views/polls/questions/_question.html.erb rename to app/components/polls/questions/question_component.html.erb diff --git a/app/components/polls/questions/question_component.rb b/app/components/polls/questions/question_component.rb new file mode 100644 index 000000000..d1a4edf27 --- /dev/null +++ b/app/components/polls/questions/question_component.rb @@ -0,0 +1,7 @@ +class Polls::Questions::QuestionComponent < ApplicationComponent + attr_reader :question + + def initialize(question:) + @question = question + end +end diff --git a/app/views/polls/show.html.erb b/app/views/polls/show.html.erb index ee4449124..29904041c 100644 --- a/app/views/polls/show.html.erb +++ b/app/views/polls/show.html.erb @@ -31,9 +31,7 @@ <% end %> <% end %> - <% @questions.each do |question| %> - <%= render "polls/questions/question", question: question %> - <% end %> + <%= render Polls::Questions::QuestionComponent.with_collection(@questions) %>