Forum: Ruby on Rails link_to helper in an Array.each

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Richard S. (Guest)
on 2008-12-18 19:44
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.
Alex 2. (Guest)
on 2008-12-19 00:13
You can try

<%=
  alphabet.collect { |letter| link_to(letter, :action => 'alphabet',
:letter => letter) }.join("<br />")
%>

- Alex
Richard S. (Guest)
on 2008-12-19 23:23
Worked like a charm, thanks!!
This topic is locked and can not be replied to.