0

Im trying to have a number of comments count on my news page but I can't seem to accomplish this

heres my view

 <div class="container">
   <br />
    <br />
   <h2 class="black">
    Recent News
    <div class="line_section"><div>
  </h2>
   <div class="row"> 
   <div class="span12">

  <ul class="recent-news"> 

  <% @news_all.each do |news| %>

   <li style="font-size: 16px; line-height: 19px; letter-spacing: 1px; font-size: 14px; color: #555; text-align: left;">
    <%= image_tag news.photo.url, class: 'pull-left', style: 'margin-right:40px; margin-top: 2px; width: 300px;' %> 
    <div style=" width: 600px; float: right;">
    <%= link_to news.title, news %> 
    <br />

     <%= link_to news.date, news, style: 'font-size: 10px; color: black; position: relative; top: 15px;' %> 

     <br /><br />
  <%= truncate news.content, length: 500 %> 
    <br />  
  <%= link_to 'Read More...', news, style: 'font-size: 12px !important;' %>
      </div>
  </li>
    <% end %> 

 <%= will_paginate @news_all %>
</div><!-- end span12 -->


 </div><!-- end row -->
</div><!-- end container -->

heres my controller

    def batnews
     @article = Article.first
     @news_all = News.all
    @news_all = News.paginate(page: params[:page], per_page: 4, :order => "created_at ASC")
    @comments = Comment.all
   end

heres my model

    class News < ActiveRecord::Base
    attr_accessible :title, :author, :date, :content, :photo
    has_attached_file :photo, :styles => { :small => '400x400' },
    :storage => :s3,
    :s3_credentials => "#{Rails.root}/config/s3.yml",
    :path => "/image/:id/:filename",
    :bucket => 'goddam_batman_pics'

     has_many :comments, as: :commentable, dependent: :destroy
   end

heres a link to the site http://www.batman-fansite.com/batnews

when i try to display the comment.count it spits out the total number of all the comments and not the comments of a particular article.......

4

1 回答 1

0

对不起,我想通了我所要做的就是

我忘记了我的新闻已经在每个 do |news| 中定义了 阻止事情谢谢

于 2012-12-17T19:32:49.150 回答