私が達成しようとしていることを人々が理解できるように、これを説明できれば幸いです。現在、複数の投稿が作成されており、公開ビュー用にこの URL に表示されています
/tynewyddnews
標準とは対照的に
/posts/:id
これは管理者ユーザーのみが利用できます
ページは 2 つに分割されています。ページの大部分を占める最新の投稿と、ページの左側にリストされている過去の投稿です。それぞれがスコープによってわずかに異なって表示されます
範囲
scope :tynewydd_posts, :include => :department, :conditions => {"departments.name" => "Ty Newydd"}, :order => "posts.published_on DESC"
最新の投稿
@tynewyddpostlatest = Post.tynewydd_posts.first
過去の投稿
tynewyddpost = Post.tynewydd_posts.reverse
tynewyddpost.pop
@tynewyddpost = tynewyddpost
私の見解では、私はそれぞれをそのようにレンダリングします
左側
<% @tynewyddpost.reverse.each do |t| %>
<%= link_to t.title, t %>
主要
<%= @tynewyddpostlatest.title %>
私が達成したいのは、左側の投稿のリンクをクリックすると、ajax を介して中央のメイン投稿の代わりにレンダリングされることです。タイトルとコメントは ajax 呼び出しを介してレンダリングされますが、クリックした投稿の写真はビューにレンダリングされていません。 .(サイズは 0x0 px ですが)
左サイドポスト
<% @tynewyddpost.reverse.each do |t| %>
<%= link_to t.title, tynewyddnews_path(:type => 'tynewyddnews'), :remote => true %>
<% end %>
tynewyddnews.js.erb
<% if params[:type] == 'tynewyddnews' %>
$('.post-item').html('<%= escape_javascript(render partial: 'tynewyddnewspost') %>');
<% end %>
部分的
<div class="post-item">
<% @tynewyddpost.each do |t| %>
<h2><%= t.title %></h2>
<div id="work-samples">
<% for photo in t.photos %>
<%= image_tag(photo.avatar.url(:news_images), :class => 'work-sample') %>
<% end %>
</div>
<p class="post-description"><%= t.comments.html_safe %></p><a class="post-more" href="#">Continue Reading »</a>
<div class="post-item-panel">
<ul>
<li class="date">
<p><%= date_output(t.published_on) %></p>
</li>
</ul>
</div>
</div>
<% end %>
どうもありがとう