現在掲示版のようなサイトをつくっていて上から順に投稿が表示されるようになっているのですが、
投稿
投稿
広告
投稿
投稿
広告
投稿.....
と広告を挿入したいのですがどうすれば良いのかがわかりません。
positing_controller.rb def index @q = Posting.search(params[:q]) @postings = @q.result(distinct: true).order("updated_at DESC").page(params[:page]).per(10) end
index.html.erb <% @postings.each do |posting| %> <div class="post post-primary"> <div class="post-heading "> <h3 class="post-title"> <%= link_to posting.title, "/postings/#{posting.id}", method: :get %> </h3> </div> <div class="post-body"> <div class="prof"> <%= posting.name%>/<%= posting.sex%>/<%= posting.age%>/<%= posting.prefecture%> </div> <hr> <div class="text"> <%= truncate(simple_format(h(posting.text)), length: 500,escape:false) %> </div> <p class="tuduki"><%= link_to "続きを読む", "/postings/#{posting.id}", method: :get %></p> <hr> <%= posting.created_at.strftime("%Y-%m-%d %H:%M:%S")%> / Comment:(<%= posting.comment%>) <%= link_to "返信", "postings/#{posting.id}/comments/new", method: :get,:class =>'btn btn-primary btn-sm',:style=>"margin-right:5px"%><%= link_to "削除", "postings/#{posting.id}/delete", method: :get,:class =>'btn btn-default btn-sm' %> </div>
コントローラーとhtmlはこんな感じです。
それと広告のパターンを何種類か用意しておいてランダムで表示させるようにしたいです。
どうすれば実現できるでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/15 12:37
2017/04/15 13:06
2017/04/15 15:03