Can I make an array of links using link_to in Rails?

前端 未结 5 1918
予麋鹿
予麋鹿 2021-02-19 13:29

I have a list of values in url/title pairs that I\'d like to display. (More specifically, each object has its own list of links, some with 0, some with 1, some with more.) I w

5条回答
  •  花落未央
    2021-02-19 13:56

    Use safe_join combined with html_safe on the separator string.

    Example:

    <%= safe_join(links.map { |l| link_to(l.title, l.url) }, ", ".html_safe) %>
    

提交回复
热议问题