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">
|
<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>
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<%= f.select :locale, I18n.available_locales %>
|
<%= 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 %>
|
<%= form_tag(admin_site_customization_update_heading_content_block_path(content_block.id), method: "put") do %>
|
||||||
<%= render "shared/errors", resource: @content_block %>
|
<%= render "shared/errors", resource: content_block %>
|
||||||
|
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<%= label_tag :name %>
|
<%= 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>
|
||||||
<div class="small-12 medium-6 column">
|
<div class="small-12 medium-6 column">
|
||||||
<%= label_tag :locale %>
|
<%= 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>
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= label_tag :body %>
|
<%= 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">
|
<div class="small-12 medium-6 large-3">
|
||||||
<%= button_tag t("admin.menu.site_customization.buttons.content_block.update"), class: "button success expanded" %>
|
<%= button_tag t("admin.menu.site_customization.buttons.content_block.update"), class: "button success expanded" %>
|
||||||
</div>
|
</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
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@selected_content_block = @content_block.name
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@@ -71,7 +70,6 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati
|
|||||||
|
|
||||||
def edit_heading_content_block
|
def edit_heading_content_block
|
||||||
@content_block = Budget::ContentBlock.find(params[:id])
|
@content_block = Budget::ContentBlock.find(params[:id])
|
||||||
@selected_content_block = "hcb_#{@content_block.heading_id}"
|
|
||||||
@is_heading_content_block = true
|
@is_heading_content_block = true
|
||||||
render :edit
|
render :edit
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<% if @is_heading_content_block %>
|
<% if @is_heading_content_block %>
|
||||||
<%= render "form_heading_content_block" %>
|
<%= render Admin::SiteCustomization::ContentBlocks::FormHeadingContentBlockComponent.new(@content_block) %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= render "form_content_block" %>
|
<%= render Admin::SiteCustomization::ContentBlocks::FormContentBlockComponent.new(@content_block) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user