Add name attribute to heading content blocks
This way we can simplify the code and don't have to rely on `.try` statements which are confusing and so we don't allow them in the `Rails/SafeNavigation` Rubocop rule.
This commit is contained in:
@@ -77,7 +77,7 @@ class Admin::SiteCustomization::ContentBlocksController < Admin::SiteCustomizati
|
|||||||
if @content_block.is_a? Budget::ContentBlock
|
if @content_block.is_a? Budget::ContentBlock
|
||||||
@selected_content_block = "hcb_#{@content_block.heading_id}"
|
@selected_content_block = "hcb_#{@content_block.heading_id}"
|
||||||
else
|
else
|
||||||
@selected_content_block = @content_block.heading.name
|
@selected_content_block = @content_block.name
|
||||||
end
|
end
|
||||||
@is_heading_content_block = true
|
@is_heading_content_block = true
|
||||||
render :edit
|
render :edit
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ class Budget
|
|||||||
validates :heading, presence: true, uniqueness: { scope: :locale }
|
validates :heading, presence: true, uniqueness: { scope: :locale }
|
||||||
|
|
||||||
belongs_to :heading
|
belongs_to :heading
|
||||||
|
delegate :name, to: :heading, allow_nil: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<% provide :title do %>
|
<% provide :title do %>
|
||||||
<%= t("admin.header.title") %> - <%= t("admin.menu.site_customization.content_blocks") %> - <%= @content_block.try(:name) || @content_block.heading.try(:name) %> (<%= @content_block.locale %>)
|
<%= t("admin.header.title") %> - <%= t("admin.menu.site_customization.content_blocks") %> - <%= @content_block.name %> (<%= @content_block.locale %>)
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= back_link_to admin_site_customization_content_blocks_path %>
|
<%= back_link_to admin_site_customization_content_blocks_path %>
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% @headings_content_blocks.each do |content_block| %>
|
<% @headings_content_blocks.each do |content_block| %>
|
||||||
<tr id="<%= dom_id(content_block) %>">
|
<tr id="<%= dom_id(content_block) %>">
|
||||||
<td><%= link_to "#{content_block.heading.name} (#{content_block.locale})", admin_site_customization_edit_heading_content_block_path(content_block) %></td>
|
<td><%= link_to "#{content_block.name} (#{content_block.locale})", admin_site_customization_edit_heading_content_block_path(content_block) %></td>
|
||||||
<td><%= raw content_block.body %></td>
|
<td><%= raw content_block.body %></td>
|
||||||
<td>
|
<td>
|
||||||
<%= render Admin::TableActionsComponent.new(
|
<%= render Admin::TableActionsComponent.new(
|
||||||
|
|||||||
@@ -19,4 +19,18 @@ describe Budget::ContentBlock do
|
|||||||
heading: heading_content_block_en.heading, locale: "es")
|
heading: heading_content_block_en.heading, locale: "es")
|
||||||
expect(valid_block).to be_valid
|
expect(valid_block).to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#name" do
|
||||||
|
it "uses the heading name" do
|
||||||
|
block = Budget::ContentBlock.new(heading: Budget::Heading.new(name: "Central"))
|
||||||
|
|
||||||
|
expect(block.name).to eq "Central"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nil on new records without heading" do
|
||||||
|
block = Budget::ContentBlock.new
|
||||||
|
|
||||||
|
expect(block.name).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user