我试图在我的新闻页面上看到一些评论,但我似乎无法完成此任务
继承人的观点
<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 :(得分:0)
抱歉,我认为我所要做的就是
我忘了我的新闻已经在每个do | news |中定义了块事谢谢你