Ruby on rails 如何在ruby rails上显示注释数
我试图让我的新闻页面上有很多评论,但我似乎无法做到这一点 这是我的观点Ruby on rails 如何在ruby rails上显示注释数,ruby-on-rails,Ruby On Rails,我试图让我的新闻页面上有很多评论,但我似乎无法做到这一点 这是我的观点 <div class="container"> <br /> <br /> <h2 class="black"> Recent News <div class="line_section"><div> </h2> <div class="row"> <div class
<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 -->
这是我的模型
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
class新闻{:small=>'400x400'},
:storage=>:s3,
:s3_credentials=>“#{Rails.root}/config/s3.yml”,
:path=>“/image/:id/:filename”,
:bucket=>“该死的蝙蝠侠”
有很多:注释,如::可注释,依赖::销毁
结束
这是该网站的链接
当我试图显示comment.count时,它会显示所有评论的总数,而不是某篇文章的评论……抱歉,我发现我所要做的只是
我忘了我的新闻已经在每个do | news | block thing中定义了谢谢如果它被解决了,那么请将它标记为这样并接受你的答案(或撤回问题)。对不起,你现在是对的-你应该能够在2天后接受。然而,在这种情况下,删除你的问题可能更好,因为它不太可能帮助其他人。。。
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