Link_to helper in an Array.each


#1

Is it possible to render a link_to element on a webpage using a .each
from an array? Such as

<% Alphabet = [‘A’,‘B’,‘C’,‘D’…,‘Z’] %>

<%= Alphabet.each{|letter| link_to '#{letter}, :action => 'alphabet,
:letter => letter %>

to replace:

<% for letter in Alphabet %>
<%= link_to '#{letter}, :action => ‘alphabet’, :letter => letter %>
<% end %>

This obviously isn’t a matter of life and death, but i prefer to use
blocks whenever possible.


#2

You can try

<%=
alphabet.collect { |letter| link_to(letter, :action => ‘alphabet’,
:letter => letter) }.join("
")
%>

  • Alex

#3

Worked like a charm, thanks!!