Mathieu Bertin Mathieu Bertin - 5 months ago 32
Ruby Question

Using a custom tag helper for ruby on rails with a bootstrap navbar

My problem is that I can't get this helper tag to display at all.

So in application_helper.rb I want to have a

<% nav_link(name, path) %>
tag helper to append bootstrap's
.active
class dynamically.

My code is the following:

def nav_link(name, path)
content_tag(:li, :class => active_class(path)) do
link_to name, path
end
end

def active_class(path)
(current_page?(path) ? "active" : "").html_safe
end


and I would like to use it like so

<% nav_link("Users", users_path) %>


My hunch is that there's a variable somewhere that's not properly sanitized. How do I fix this? Is the html_safe call necessary?

Answer

Unless it's a typo, you should use <%= nav_link("Users", users_path) %>.
Without =, nothing will be displayed