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.
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2008-12-18 18: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.
E1e2dd8c03c8e9e0680cfd802df0a04b?d=identicon&s=25 Alex 2k8 (alex_2k8)
on 2008-12-18 23:13
You can try

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

- Alex
71ee1809f53df0a2b4dac0530f630933?d=identicon&s=25 Richard Schneeman (snowmaninthesun)
on 2008-12-19 22:23
Worked like a charm, thanks!!
This topic is locked and can not be replied to.