Tag helper in helper module is not work correctly (rails)

Tag helper in helper module is not work correctly (rails)

Problem Description:

I want to render html to the view using the tag helper with the method declared in the helper module, but it doesn’t work.
html code I’d like to render is following:

<span class="flex w-5 h-5 ml-3">
  <span class="animate-ping inline-flex h-full w-full rounded-full aspect-square bg-indigo-400 opacity-75"></span>
  <span class="relative inline-flex w-5 h-5 rounded-full bg-indigo-500 text-gray-200 justify-center aspect-square right-5">
    <%= current_user_active_count %>
  </span>
</span>

The code actually written in the helper is below:

tag.span class: "flex w-5 h-5 ml-3" do
  tag.span class: "animate-ping inline-flex h-full w-full rounded-full aspect-square bg-indigo-400 opacity-75"
  tag.span current_user_active_count, class: "relative inline-flex w-5 h-5 rounded-full bg-indigo-500 text-gray-200 justify-center aspect-square right-5"
end

The html rendered by this code is below:

<span class="flex w-5 h-5 ml-3">
  <span class="relative inline-flex w-5 h-5 rounded-full bg-indigo-500 text-gray-200 justify-center aspect-square right-5">
    <%= current_user_active_count %>
  </span>
</span>

As shown above, the first tag of the two nested tags is ignored and only the second tag is rendered.
I think it’s a writing style problem, but how can I render the desired html?
I would appreciate it if you could advise me.

Solution – 1

You can use concat to accumulate content into the output buffer:

tag.span class: "flex w-5 h-5 ml-3" do
  concat tag.span(class: "animate-ping inline-flex h-full w-full rounded-full aspect-square bg-indigo-400 opacity-75")
  concat tag.span(current_user_active_count, class: "relative inline-flex w-5 h-5 rounded-full bg-indigo-500 text-gray-200 justify-center aspect-square right-5")
end
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept
Reject