Display comments count

This commit is contained in:
Marcin Kulik 2012-04-09 16:46:08 +02:00
parent f4856407c1
commit 45dd308186
4 changed files with 12 additions and 2 deletions

View File

@ -5,7 +5,7 @@ class Comment < ActiveRecord::Base
validates :user_id, :presence => true
belongs_to :user
belongs_to :asciicast
belongs_to :asciicast, :counter_cache => true
attr_accessible :body

View File

@ -19,4 +19,8 @@
<% if asciicast.description.present? %>
<p class="description"><%= asciicast.description %></p>
<% end %>
<% if asciicast.comments_count > 0 %>
<p><%= link_to "#{asciicast.comments_count} comments", asciicast_path(asciicast, :anchor => 'comments') %></p>
<% end %>
</li>

View File

@ -0,0 +1,5 @@
class AddCommentsCountToAsciicast < ActiveRecord::Migration
def change
add_column :asciicasts, :comments_count, :integer, :null => false, :default => 0
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120406152447) do
ActiveRecord::Schema.define(:version => 20120409142151) do
create_table "asciicasts", :force => true do |t|
t.integer "user_id"
@ -35,6 +35,7 @@ ActiveRecord::Schema.define(:version => 20120406152447) do
t.boolean "featured", :default => false
t.string "username"
t.text "snapshot"
t.integer "comments_count", :default => 0, :null => false
end
add_index "asciicasts", ["created_at"], :name => "index_asciicasts_on_created_at"