Link_to helper in an Array.each

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.

You can try

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

  • Alex

Worked like a charm, thanks!!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs