【问题标题】:How do I render a content feed into multiple columns?如何将内容提要呈现到多个列中?
【发布时间】:2012-02-13 15:54:56
【问题描述】:

我是编程新手,刚刚完成 RailsTutorial,现在正在尝试使用 Rails 构建一个 Pinterest 类型的网站。

我希望主站点通过多列和无限循环显示项目,例如:

1 2 3 4 5

6 7 8 9 10

。 . . . .

我有我想要的布局,但不知道如何将内容提要分成多个 div。

home.html.erb(我知道这是错误的)

<% if signed_in? %>

  <div id="container" summary="For signed-in users">
    <div class="news-column1"><%= render 'shared/feed' %></div>
    <div class="news-column2"><%= render 'shared/feed' %></div>
    <div class="news-column3"><%= render 'shared/feed' %></div>
    <div class="news-column4"><%= render 'shared/feed' %></div>
    <div class="news-column5"><%= render 'shared/feed' %></div>
<% else %>
...
<% end %>

_feed.html.erb

<% if @feed_items.any? %>
  <%= render :partial => 'shared/feed_item', :collection => @feed_items %>
<% end %>

_feed_item.html.erb

<div class="news">
    <div class="comments">
        <%= wrap(feed_item.content) %>
    </div>
    <div class="stats">
        #Likes, #Comments, #Repins
    </div>
    <div class="points">
    <%= link_to feed_item.user.name, feed_item.user %>
    </div>
    <div class="author">
    Posted <%= time_ago_in_words(feed_item.created_at) %> ago.
    </div>
</div>
<% if current_user?(feed_item.user) %>
  <div>
    <%= link_to "delete", feed_item, :method => :delete,
                                     :confirm => "You sure?",
                                     :title => feed_item.content %>
  </div>
<% end %>

【问题讨论】:

    标签: ruby-on-rails partial renderpartial


    【解决方案1】:

    Ryan Bates 向您展示了如何做到这一点here

    代码如下:

    <table>
    <% @tasks.in_groups_of(5, false) do |row_tasks| %>
      <tr>
        <% for task in row_tasks %>
          <td><%= task.name %></td>
        <% end %>
      </tr>
    <% end %>
    </table>
    

    【讨论】:

      【解决方案2】:

      这似乎很适合我:

      <div class="container-fluid">
        <% @buildings.each do |building| %>
          <div class="col-md-3">
              <%= building.name %>
          </div>
        <% end %>
      </div>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-13
        • 2015-04-20
        • 2016-03-15
        • 1970-01-01
        • 2020-07-23
        • 1970-01-01
        相关资源
        最近更新 更多