简体   繁体   中英

Show collection view by using scss file in rails

I' like to show the question model information as collection view like picture1. However, I have no idea how to do it. My present view is like picture2. I want to show each question body as collection view, not table view. The following is present scss and view file. Could you tell me how to achieve the collection view on rails?

#app/assets/stylesheets/custom.css.scss

.questions {
  list-style: none;
  margin: 30px 0 0 0;
  color: #000000;
  // width:300px;
  // height:100px;
  // background:gray;
  box-shadow: 0 2px 4px 4gba(0,0,0,0.2);

  div {
    display:inline;
  }

  li {
    padding: 50px 0;
    border-top: 1px solid #e8e8e8;
  }
}
.content {
  display: block;
}

#app/views/questions/show.html.erb
<div class="row">
  <div class="span8">
    <h3>Popular</h3>
    <div class = "questions">
      <%= render @questions %>
    </div>
  </div>
</div>

Picture1 图片1

Picture2 图片2

You'll need to read bootstrap's doc ( http://getbootstrap.com/css/ ). You can use for instance Boostrap's thumbnails and modify the styles. By adding col-md-4 like I did, you'll have 3 questions per row.

<div class="row">
   <h3>Popular</h3>
   <%= render @questions %>
</div>

In _question.html.erb:

  <div class="col-md-4">
     <%= link_to question, class: "thumbnail" do %>
       <%= image_tag question.image %>
     <% end %>
  </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM