Mathieu Bertin Mathieu Bertin - 1 year ago 110
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
class dynamically.

My code is the following:

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

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

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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download