简体   繁体   中英

Ruby enumerator in Rails template

<ul>
<% for file in @files %>
 <li><%= file %></li>
<% end %>
</ul>

output :

  • file1
  • file2

    but if i want to use enumerator :

     <% @files.each{|file| file} %> 

    output : ['file1', 'file2']

    I can not get the output as a <\\li> list.

    My question is is it possible to get the list output using enumeration? if so how?? I am a beginner at rails.

  • <% @files.each do |file| %>
      <li><%= file %></li>
    <% end %>
    

    For the sake of one liner, you could do:

    <%=raw @files.map {|file| content_tag(:li, file)}.join %>
    
    #mix
    <% @files.each do |file| %> <%= content_tag(:li, file) %> <% end %>
    

    But really , don't !

    The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM