Move banner form partial to a component
Other than simplifying the controller, this'll make it easier to write tests for this code.
This commit is contained in:
@@ -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 %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-3 column">
|
||||
@@ -36,7 +36,7 @@
|
||||
<div class="row">
|
||||
<fieldset class="small-12 column">
|
||||
<legend><%= t("admin.banners.banner.sections_label") %></legend>
|
||||
<%= 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 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<%= render Shared::BannerComponent.new(@banner) %>
|
||||
<%= render Shared::BannerComponent.new(banner) %>
|
||||
</div>
|
||||
<% end %>
|
||||
15
app/components/admin/banners/form_component.rb
Normal file
15
app/components/admin/banners/form_component.rb
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
|
||||
<h1><%= t("admin.banners.edit.editing") %></h1>
|
||||
|
||||
<%= render "form" %>
|
||||
<%= render Admin::Banners::FormComponent.new(@banner) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
|
||||
<h1><%= t("admin.banners.new.creating") %></h1>
|
||||
|
||||
<%= render "form" %>
|
||||
<%= render Admin::Banners::FormComponent.new(@banner) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user