辅助函数Rails 3失败

时间:2012-09-26 22:55:02

标签: ruby-on-rails ruby-on-rails-3 view-helpers

我做完了!非常幸运,我正在研究它大约三天,在我的节目视图中重写代码如下:

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

现在的问题是,在信息下面显示了一个错误的代码,这段代码是我所有标签的列表:

[#<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">]

你怎么看?

1 个答案:

答案 0 :(得分:0)

<%= @tags.each do |z| %>更改为<% @tags.each do |z| %>。 =符号表示渲染到html,因此它显示@tags变量。