Rails:从集合中创建表

时间:2012-04-02 04:27:38

标签: ruby-on-rails

我正在使用Forem博客宝石。它以这种方式呈现特定主题的帖子。

<%= render :partial => "forem/posts/post", :collection => @posts %>

有没有办法让输出显示在表格中?我已将<td>标记放在下面部分的部分中,我想要分成一个表格。

我想要的行名是Name,Posted At,Message,In Reply to和Actions。

我以为我可能会做类似

的事情
@posts.each do |p|

<tr>
p
</tr>

但我无法弄清楚如何让它发挥作用

部分

<a name='post-<%= post.id %>'></a>
<div id='post_<%= post.id %>' class='post <%= cycle('odd', 'even') -%>'>


  <td>
      Name:<%= link_to_if Forem.user_profile_links, post.user, [main_app, post.user] %>
    </div>
    <div class='icon'><%#= avatar(post.user, :size => 60) %></div>

  </td>



 <td>
    <a href='#post-<%= post.id %>'>
      <time datetime="<%= post.created_at.to_s(:db) -%>"><%= "#{time_ago_in_words(post.created_at)} #{t("ago")}" %></time>
    </a>
 </td>
 <td>
    <%= forem_format(post.text) %>
 </td>

<td>
    <% if post.reply_to %>
      <span class='in_reply_to'>
        <%= link_to "#{t("forem.post.in_reply_to")} #{post.reply_to.user}", "#post-#{post.reply_to.id}" %>
      </span>
    <% end %>
</td>

<td>

    <ul class='actions'>
      <% if forem_user %>
        <% if can?(:reply, @topic) %>
          <% if @topic.can_be_replied_to? %>
            <li><%= link_to t('reply', :scope => 'forem.topic'), new_topic_post_path(@topic, :reply_to_id => post.id) %></li>
          <% end %>
          <% if @topic.can_be_replied_to? %>
            <li><%= link_to t('quote', :scope => 'forem.topic'), new_topic_post_path(@topic, :reply_to_id => post.id, :quote => true) %></li>
          <% end %>
        <% end %>
        <% if post.owner_or_admin?(forem_user) %>
          <% if can?(:edit_post, @topic.forum) %>
            <li><%= link_to t('edit', :scope => 'forem.post'), edit_topic_post_path(@topic, post) %></li>
          <% end %>
          <li><%= link_to t('delete', :scope => 'forem.topic'), topic_post_path(@topic, post), :method => :delete, :confirm => t("are_you_sure") %></li>
        <% end %>
      <% end %>
    </ul>

 </td>

  </div>
</div>

1 个答案:

答案 0 :(得分:0)

您是否尝试过添加代替部分代码的最开头?也许是在帖子循环之前?

相关问题