diff --git a/app/views/admin/banners/_form.html.erb b/app/components/admin/banners/form_component.html.erb similarity index 88% rename from app/views/admin/banners/_form.html.erb rename to app/components/admin/banners/form_component.html.erb index cd82e3f37..7468a2ff0 100644 --- a/app/views/admin/banners/_form.html.erb +++ b/app/components/admin/banners/form_component.html.erb @@ -1,8 +1,8 @@ -<%= render "shared/globalize_locales", resource: @banner %> +<%= render "shared/globalize_locales", resource: banner %> -<%= translatable_form_for [:admin, @banner] do |f| %> +<%= translatable_form_for [:admin, banner] do |f| %> - <%= render "shared/errors", resource: @banner %> + <%= render "shared/errors", resource: banner %>
@@ -36,7 +36,7 @@
<%= t("admin.banners.banner.sections_label") %> - <%= f.collection_check_boxes(:web_section_ids, @banner_sections, :id, :name) do |b| %> + <%= f.collection_check_boxes(:web_section_ids, sections, :id, :name) do |b| %> <%= b.label do %> <%= b.check_box + t("admin.banners.banner.sections.#{b.text}") %> <% end %> @@ -79,6 +79,6 @@
- <%= render Shared::BannerComponent.new(@banner) %> + <%= render Shared::BannerComponent.new(banner) %>
<% end %> diff --git a/app/components/admin/banners/form_component.rb b/app/components/admin/banners/form_component.rb new file mode 100644 index 000000000..26c51f9ba --- /dev/null +++ b/app/components/admin/banners/form_component.rb @@ -0,0 +1,15 @@ +class Admin::Banners::FormComponent < ApplicationComponent + include TranslatableFormHelper + include GlobalizeHelper + attr_reader :banner + + def initialize(banner) + @banner = banner + end + + private + + def sections + WebSection.all + end +end diff --git a/app/controllers/admin/banners_controller.rb b/app/controllers/admin/banners_controller.rb index 72b085a5d..3ae9df5f8 100644 --- a/app/controllers/admin/banners_controller.rb +++ b/app/controllers/admin/banners_controller.rb @@ -3,8 +3,6 @@ class Admin::BannersController < Admin::BaseController has_filters %w[all with_active with_inactive], only: :index - before_action :banner_sections, only: [:edit, :new, :create, :update] - respond_to :html, :js load_and_authorize_resource @@ -47,10 +45,6 @@ class Admin::BannersController < Admin::BaseController web_section_ids: []] end - def banner_sections - @banner_sections = WebSection.all - end - def resource @banner ||= Banner.find(params[:id]) end diff --git a/app/views/admin/banners/edit.html.erb b/app/views/admin/banners/edit.html.erb index 26b4f49b0..a3d17da83 100644 --- a/app/views/admin/banners/edit.html.erb +++ b/app/views/admin/banners/edit.html.erb @@ -5,6 +5,6 @@

<%= t("admin.banners.edit.editing") %>

- <%= render "form" %> + <%= render Admin::Banners::FormComponent.new(@banner) %>
diff --git a/app/views/admin/banners/new.html.erb b/app/views/admin/banners/new.html.erb index 1174fc81c..27df19519 100644 --- a/app/views/admin/banners/new.html.erb +++ b/app/views/admin/banners/new.html.erb @@ -5,6 +5,6 @@

<%= t("admin.banners.new.creating") %>

- <%= render "form" %> + <%= render Admin::Banners::FormComponent.new(@banner) %>