Fix crash voting on a heading with a content block
When voting investment projects, the sidebar was rendered without the `@heading_content_blocks` being set. That resulted in a 500 error when the heading had content blocks. By extracting the logic to a component, we make sure the heading content blocks are properly set every time this code is rendered, no matter which controller is rendering the view.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
<ul class="no-bullet categories">
|
||||
<% content_blocks.each do |content_block| %>
|
||||
<%= raw content_block.body %>
|
||||
<% end %>
|
||||
</ul>
|
||||
@@ -0,0 +1,17 @@
|
||||
class Budgets::Investments::ContentBlocksComponent < ApplicationComponent
|
||||
attr_reader :heading
|
||||
|
||||
def initialize(heading)
|
||||
@heading = heading
|
||||
end
|
||||
|
||||
def render?
|
||||
heading&.allow_custom_content && content_blocks.any?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def content_blocks
|
||||
heading.content_blocks.where(locale: I18n.locale)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user