How to put content under the first record rails 4 -
i on rails 4. have 2 resources: subarticles , articles. subarticles nested in articles so:
resources :articles resources :subarticles member put "like" => "subarticles#upvote" put "dislike" => "subarticles#downvote" end end end
on articles show page, display of subarticles. however, place of article attributes ( pictures , videos) directly under first subarticle.
i having trouble finding documentation on doing so.
also note have subarticles ordered number of votes. if 1 gets voted higher other, go top. want keep same pictures , videos right under first subarticle.
here simplified version of article show page:
<div class="row"> <div class="col-md-9"> <div class="well" style="background:white; height:230px"> <%= @article.title.titleize %><br> <%= social_share_button_tag %> </div> <% @subarticles.each |subarticle| %> <div class="well" style="background:white"> <%= subarticle.rating %><br> <%= subarticle.whyrating %><br> <div class="row" style="margin-top:40px;"> <div class="col-md-7 col-md-offset-1" style="margin-top:30px"> <%= link_to like_article_subarticle_path(@article, subarticle), class: "like", method: :put %> <button type="button" class="btn btn-success btn-lg" aria-label="left align" style="margin-right:5px"> <span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"></span> helpful </button><span class="badge" style="margin-right:10px"><%= subarticle.get_upvotes.size %></span> <% end %> <%= link_to dislike_article_subarticle_path(@article, subarticle), class: "like", method: :put %> <button type="button" class="btn btn-danger btn-lg" aria-label="left align" style="margin-right:5px"> <span class="glyphicon glyphicon-thumbs-down" aria-hidden="true"></span> unhelpful </button><span class="badge"><%= subarticle.get_downvotes.size %></span> <% end %> </div> </div> </div> <% end %> <div class="well" style="background:white; text-align:center"> <h4>pictures & videos</h4><br> <%= image_tag @article.image1(:medium) %><br> <div class="embed-responsive embed-responsive-4by3"> <iframe class="embed-responsive-item" src="<%= @article.video1 %>"></iframe> </div> </div> </div> </div>
because of @subarticles.each do
push pictures , videos way bottom. best way show first subarticle, pictures & videos, rest of subarticles?
let me know if need show other code.
<% @subarticles.each_with_index |subarticle, i| %> <div class="well" style="background:white"> ....... // subarticle contents </div> <% if i==0 %> // put articles content here <% end %> <% end %>
in way after first subarticle
if condition checks loop index, loop index 0, first show subarticle
first content, index 0 shows article
contents.
Comments
Post a Comment