Hello. As of this writing, I’m using Hanami View via the main
branch (SHA: bc231ce090f7ce805f88ce9cc32959f647cdf6e9) and wondering if a View Part can use helpers? Here’s a snippet:
require "htmx"
module Main
module Views
module Parts
class Task < Hanami::View::Part
include Hanami::View::Helpers::TagHelper
def delete_button
tag.button(
"Delete",
type: "submit",
class: "button button-decline",
**HTMX[target: "closest .task", delete: "/tasks/#{value.id}"]
)
end
end
end
end
end
Notice that I include the TagHelper
and then attempt to have my part build a button. There are two issues I run into when doing this. The first is the exception shown in the browser:
undefined local variable or method `_options'
../3.2.0/gems/hanami-2.0.3/lib/hanami/extensions/view/context.rb:39:in `inflector'
The second is with the associated spec:
it "answers delete button" do
expect(part.delete_button.to_s).to eq(
%(<button type="submit" class="button button-decline" hx-target="closest .task" ) +
%(hx-delete="/tasks/1">Delete</button>)
)
end
…which fails with this exception:
Hanami::View::RenderingMissingError:
a +rendering+ must be provided
# ./slices/main/views/parts/task.rb:20:in `delete_button'
Is it possible I have a View/Part misconfiguration in my application or are helpers solely regulated to Views and I’m misunderstanding Parts entirely?