From 3c05cdec58db5cbd43d2b2b14f300b9af9324391 Mon Sep 17 00:00:00 2001 From: Lucian Ghinda Date: Thu, 7 Sep 2023 06:18:44 +0300 Subject: [PATCH] Refactor Search Form in Screncasts with SearchComponent Description: This commit replaces the search form in app/views/screencasts/index.html.erb with the SearchComponent. The SearchComponent encapsulates the search form logic, making the code more readable and easier to change. It also takes care of HTML escaping the search_term, improving security. The form is now rendered inside a
instead of a to follow HTML best practices. --- app/views/screencasts/index.html.erb | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/app/views/screencasts/index.html.erb b/app/views/screencasts/index.html.erb index 292de2fd..54707fec 100644 --- a/app/views/screencasts/index.html.erb +++ b/app/views/screencasts/index.html.erb @@ -1,34 +1,19 @@ <% content_for :hero do %> <%= render "shared/page_title", title: "Screencasts about Ruby and Ruby on Rails", description: "If you're looking for some helpful resources on learning Ruby and Ruby on Rails development, I recommend checking out some screencast tutorials. There's a lot of great information out there that can help you get started and become a better developer. Happy learning!", count: "#{Screencast.count} courses" %> <% end %> - <% content_for :content do %> <% if params[:search_term].present? %>
Search Term: <%= params[:search_term] %>
<% end %> -
- -

All Screencasts

-
- - - <%= form_tag(screencasts_path, method: "get", id: 'search_form', remote: true) do %> -
- - <%= text_field_tag(:search_term, nil, placeholder: 'Search name', class: 'form-control', value: html_escape(params[:search_term])) %> - - - - <%= link_to screencasts_path, type: :submit, class: "btn btn-warning", id: "clear-search-btn", title: "Reset", style: "margin-left: 10px; color: black" do %> X <% end %> - -
- <% end %> -
+
+

All Screencasts

+
+
+ <%= render SearchComponent.new(path: screencasts_path, search_term: params[:search_term]) %> +
- <%= render partial: "screencasts/list", locals: { list: @screencasts } %> <% end %> -