2012-12-17 64 views
0

我试着去算有我的新闻页面上的一些评论,但我似乎无法做到这一点如何显示评论红宝石在轨道上数

继承人我看来

<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 --> 

我的继承人控制器

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 

我的继承人模型

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 

继承人的链接网站 http://www.batman-fansite.com/batnews

当我尝试以显示它吐出的所有评论总数和特定物品的不是评论comment.count .......

回答

0

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

我忘记了自己的新闻已经在做每一个内定义|新闻|块的东西谢谢

+1

如果它解决了,那么请把它标记为本身和接受你的答案(或退出的问题)。 – PinnyM

+0

我无法接受我自己的回答 – user1502223

+0

对不起,您目前正确 - 2天后您应该可以接受。但是,在这种情况下,删除问题可能会更好,因为它不太可能帮助其他人...... – PinnyM