ruby - Link_to and Ajax request Rails -


hopefully can explain people can understand trying achieve. have multiple posts being created , shown @ url public view

/tynewyddnews 

as opposed standard

/posts/:id 

which available admin user

the page split 2, latest post on taking of page , historical posts listed down left hand side of page, each rendered different through scope

scope

scope :tynewydd_posts, :include => :department, :conditions => {"departments.name" => "ty newydd"}, :order => "posts.published_on desc" 

latest post

@tynewyddpostlatest = post.tynewydd_posts.first 

historical posts

tynewyddpost = post.tynewydd_posts.reverse tynewyddpost.pop @tynewyddpost = tynewyddpost 

in view render each so

left hand side

<% @tynewyddpost.reverse.each |t| %> <%= link_to t.title, t %> 

main

<%= @tynewyddpostlatest.title %> 

what achieve when clicking link post on left hand side render in place of main post in center via ajax. have come far works point, title , comments render via ajax call photos post have clicked haven't rendered in view, though when in firebug showing being rendered.(though have size of 0x0 px)

left hand side posts

<% @tynewyddpost.reverse.each |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 %> 

partial

<div class="post-item">   <% @tynewyddpost.each |t| %>    <h2><%= t.title %></h2>     <div id="work-samples">       <% 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&nbsp;&raquo;</a>    <div class="post-item-panel">       <ul>        <li class="date">         <p><%= date_output(t.published_on) %></p>        </li>       </ul>   </div> </div>   <% end %> 

many thanks

can remove line firstly:

<%= @tynewyddpostlatest.title %> 

and try if error keeps showing. if does, can remove:

<% @tynewyddpost.reverse.each |t| %> <%= link_to t.title, t %> 

does error still show?


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -