Move content blocks forms partials to components
This way we can simplify the controller a little bit, and it'll be easier to write tests for them when we change the code.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<%= form_for [:admin, @content_block], html: { class: "edit_page" } do |f| %>
|
||||
<%= form_for [:admin, content_block], html: { class: "edit_page" } do |f| %>
|
||||
|
||||
<%= render "shared/errors", resource: @content_block %>
|
||||
<%= render "shared/errors", resource: content_block %>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.select :name, options_for_select(valid_blocks, @selected_content_block) %>
|
||||
<%= f.select :name, options_for_select(valid_blocks, selected_content_block) %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.select :locale, I18n.available_locales %>
|
||||
@@ -0,0 +1,14 @@
|
||||
class Admin::SiteCustomization::ContentBlocks::FormContentBlockComponent < ApplicationComponent
|
||||
attr_reader :content_block
|
||||
use_helpers :valid_blocks
|
||||
|
||||
def initialize(content_block)
|
||||
@content_block = content_block
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def selected_content_block
|
||||
content_block.name
|
||||
end
|
||||
end
|
||||
@@ -1,17 +1,17 @@
|
||||
<%= form_tag(admin_site_customization_update_heading_content_block_path(@content_block.id), method: "put") do %>
|
||||
<%= render "shared/errors", resource: @content_block %>
|
||||
<%= form_tag(admin_site_customization_update_heading_content_block_path(content_block.id), method: "put") do %>
|
||||
<%= render "shared/errors", resource: content_block %>
|
||||
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= label_tag :name %>
|
||||
<%= select_tag :name, options_for_select(valid_blocks, @selected_content_block) %>
|
||||
<%= select_tag :name, options_for_select(valid_blocks, selected_content_block) %>
|
||||
</div>
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= label_tag :locale %>
|
||||
<%= select_tag :locale, options_for_select(I18n.available_locales, @content_block.locale.to_sym) %>
|
||||
<%= select_tag :locale, options_for_select(I18n.available_locales, content_block.locale.to_sym) %>
|
||||
</div>
|
||||
<div class="small-12 column">
|
||||
<%= label_tag :body %>
|
||||
<%= text_area_tag :body, @content_block.body, rows: 10 %>
|
||||
<%= text_area_tag :body, content_block.body, rows: 10 %>
|
||||
<div class="small-12 medium-6 large-3">
|
||||
<%= button_tag t("admin.menu.site_customization.buttons.content_block.update"), class: "button success expanded" %>
|
||||
</div>
|
||||
@@ -0,0 +1,14 @@
|
||||
class Admin::SiteCustomization::ContentBlocks::FormHeadingContentBlockComponent < ApplicationComponent
|
||||
attr_reader :content_block
|
||||
use_helpers :valid_blocks
|
||||
|
||||
def initialize(content_block)
|
||||
@content_block = content_block
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def selected_content_block
|
||||
"hcb_#{content_block.heading_id}"
|
||||
end
|
||||
end
|
||||
@@ -34,7 +34,6 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati
|
||||
end
|
||||
|
||||
def edit
|
||||
@selected_content_block = @content_block.name
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -71,7 +70,6 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati
|
||||
|
||||
def edit_heading_content_block
|
||||
@content_block = Budget::ContentBlock.find(params[:id])
|
||||
@selected_content_block = "hcb_#{@content_block.heading_id}"
|
||||
@is_heading_content_block = true
|
||||
render :edit
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<% if @is_heading_content_block %>
|
||||
<%= render "form_heading_content_block" %>
|
||||
<%= render Admin::SiteCustomization::ContentBlocks::FormHeadingContentBlockComponent.new(@content_block) %>
|
||||
<% else %>
|
||||
<%= render "form_content_block" %>
|
||||
<%= render Admin::SiteCustomization::ContentBlocks::FormContentBlockComponent.new(@content_block) %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user