Rodrigo’s tip has a problem: each link will have a UL + LI, but I agree with him that using ERB (or HAML, or SLIM) is better. If for some reason you need to do this with ruby, maybe this will help:
def menu(links = [])
content_tag :ul do
links.map do |link|
content_tag :li do
link_to link[:label], link[:href]
end
end
end
end
calling for:
<% links = [] %>
<% links << { label: 'google', href: 'https://google.com' } %>
<% links << { label: 'facebook', href: 'https://facebook.com' } %>
<% links << { label: 'twitter', href: 'https://twitter.com' } %>
<% links << { label: 'logout', href: logout_path %>
<%= menu(links) %>
I believe the editing of my answer is incorrect. How we concatenate String with
ActiveSupport::SafeBuffer
, the result will be a String– Rodrigo