0

我刚开始使用 Rails(作为一个完全的编码新手),虽然我有这个代码可以工作,但我知道它会让有经验的编码员畏缩。请帮我更好地重写这个。具体来说,让第一张图片成为链接的一部分

<table class="table table-hover">
    <tr id="topbar"><th width="60%">Name</th> 
    <th width="10%">Size</th>
    <th width="20%">Modified</th>
    <th width="5%"></th>
    <th width="5%"></th></tr>
<% @folders.each do |folder| %>
    <tr>
     <td width="60%"><img src="https://s3-us-west-2.amazonaws.com/images/folder.gif"> <%= link_to folder.name, browse_path(folder) %></td>
     <td width="10%">-</td>
     <td width="20%">-</td>     
     <td width="5%"><%= link_to image_tag("https://s3-us-west-2.amazonaws.com/images/page_edit.gif"), rename_folder_path(folder) %></td> 
     <td width="5%"><%= link_to image_tag("https://s3-us-west-2.amazonaws.com/images/action_stop.gif"), folder, :confirm => 'Are you sure you want to delete the folder and all of its contents?', :method => :delete %></td>
    </tr>
<% end %> 
4

3 回答 3

2

可以使用原始助手。

<td width="60%">
  <%= link_to raw("#{image_tag('https://s3-us-west-2.amazonaws.com/images/folder.gif')} #{folder.name}"), browse_path(folder) %>
</td>
于 2013-05-05T16:56:46.610 回答
0
<%= link_to " <td width=\"60%\"><img src=\"https://s3-us-west-2.amazonaws.com/images/folder.gif\">#{link_to folder.name, browse_path(folder)}</td><td width=\"10%\">-</td><td width=\"20%\">-</td>" %>

未经测试,但我想类似的东西应该可以工作。

于 2013-05-05T04:15:08.310 回答
0

您可以使用 ruby​​ 的块语法将图像和名称作为块传递,方法是使用 do 和 end 并将路径作为 link_to 的参数传递。

<td width="60%">
  <%= link_to browse_path(folder) do %>
    <img src="https://s3-us-west-2.amazonaws.com/images/folder.gif">
    <%= folder.name %>
  <% end %>
</td>
于 2013-05-05T05:37:48.770 回答