2013-05-05 33 views
0

我剛剛開始與Rails(作爲一個完整的新手來編碼),並且,雖然我有這個代碼的工作,我知道它會讓經驗豐富的編碼器畏縮。請幫我改寫一下。具體來說,使得第一圖像變成鏈路更好的方式來寫一個新手的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 %> 
+0

您的文章的標題應該是問題的摘要,而不是您對此的看法。在你的問題下面有一個編輯鏈接,你可以用它來選擇一個更合適的標題 – 2013-05-05 16:59:35

回答

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>" %> 

未經檢驗的一部分,但我想像類似的應該工作的東西。

+0

爲了評估HTML到link_to,使用「raw」=><%= link_to raw(「」),path%> – hypee 2013-05-05 16:53:11

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> 
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> 
相關問題