2012-09-26 58 views
0

我已經完成了!很幸運,我的工作就可以了三天左右,是什麼在我的節目鑑於這樣的重寫了代碼:輔助功能Rails 3失敗

<ul> 
<%= @tags.each do |z| %> 
    <% if z.name == @tag.name %> 
     <li style="visibility:hidden"><%= id = z.tagable_id %></li> 
     <p>User name:<strong> <%= find_user(id)%></strong></p> 
     <li>Post content:<strong><%= post = find_post(id)%></strong></li> 
    <% end %> 
<% end%> 

</ul> 

現在的問題是,下面的信息的wried代碼顯示,該代碼清單我有的所有標籤:

[#<Tag id: 1, name: "septiembre", tagable_id: 301, tagable_type: "Post", created_at:  "2012-09-25 23:43:02", updated_at: "2012-09-25 23:43:02">, #<Tag id: 2, name: "Septiembre", tagable_id: 302, tagable_type: "Post", created_at: "2012-09-26 15:40:54", updated_at: "2012-09-26 15:40:54">, #<Tag id: 3, name: "Octubre", tagable_id: 302, tagable_type: "Post", created_at: "2012-09-26 17:11:04", updated_at: "2012-09-26 17:11:04">, #<Tag id: 4, name: "septiembre", tagable_id: 302, tagable_type: "Post", created_at: "2012-09-26 18:45:54", updated_at: "2012-09-26 18:45:54">, #<Tag id: 5, name: "septiembre\r\n", tagable_id: 303, tagable_type: "Post", created_at: "2012-09-27 00:09:36", updated_at: "2012-09-27 00:09:36">, #<Tag id: 6, name: "septiembre", tagable_id: 304, tagable_type: "Post", created_at: "2012-09-27 00:10:26", updated_at: "2012-09-27 00:10:26">, #<Tag id: 7, name: "Octubre", tagable_id: 305, tagable_type: "Post", created_at: "2012-09-27 00:10:47", updated_at: "2012-09-27 00:10:47">] 

您認爲?

+0

你的結果是完全邏輯的:你逐個提取元素,然後嘗試將每個元素與一些初始集合進行匹配。顯然,一個元素將永遠匹配自己,所以你得到它們全部 – apneadiving

回答

0

更改<%= @tags.each do |z| %><% @tags.each do |z| %>。 =符號表示呈現給html,因此它顯示@tags變量。

+0

它的工作原理!感謝:D –