Display a diary entry count on the user page
This commit is contained in:
parent
067ff20504
commit
67a03d44a1
4 changed files with 22 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
class DiaryEntry < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :user, :counter_cache => true
|
||||
belongs_to :language, :foreign_key => 'language_code'
|
||||
|
||||
|
||||
has_many :comments, :class_name => "DiaryComment",
|
||||
:include => :user,
|
||||
:order => "diary_comments.id"
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<span class='count-number'><%= number_with_delimiter(@user.traces.size) %></span>
|
||||
|
|
||||
<%= link_to t('user.view.my diary'), :controller => 'diary_entry', :action => 'list', :display_name => @user.display_name %>
|
||||
<span class='count-number'><%= number_with_delimiter(@user.diary_entries.size) %></span>
|
||||
|
|
||||
<%= link_to t('user.view.my comments' ), :controller => 'diary_entry', :action => 'comments', :display_name => @user.display_name %>
|
||||
|
|
||||
|
@ -37,6 +38,7 @@
|
|||
<%= link_to t('user.view.send message'), :controller => 'message', :action => 'new', :display_name => @this_user.display_name %>
|
||||
|
|
||||
<%= link_to t('user.view.diary'), :controller => 'diary_entry', :action => 'list', :display_name => @this_user.display_name %>
|
||||
<span class='count-number'><%= number_with_delimiter(@this_user.diary_entries.size) %></span>
|
||||
|
|
||||
<%= link_to t('user.view.comments'), :controller => 'diary_entry', :action => 'comments', :display_name => @this_user.display_name %>
|
||||
|
|
||||
|
@ -95,7 +97,7 @@
|
|||
</p>
|
||||
|
||||
<% if @user and @user.administrator? -%>
|
||||
<p><b><%= t 'user.view.email address' %></b> <%= @this_user.email %></p>
|
||||
<p><b><%= t 'user.view.email address' %></b> <%= @this_user.email %></p>
|
||||
<% unless @this_user.creation_ip.nil? -%>
|
||||
<p><b><%= t 'user.view.created from' %></b> <%= @this_user.creation_ip %></p>
|
||||
<% end -%>
|
||||
|
|
13
db/migrate/20121005195010_add_diary_entry_counter_caches.rb
Normal file
13
db/migrate/20121005195010_add_diary_entry_counter_caches.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class AddDiaryEntryCounterCaches < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :users, :diary_entries_count, :integer, :null => false, :default => 0
|
||||
|
||||
DiaryEntry.group(:user_id).pluck(:user_id).each do |user_id|
|
||||
User.reset_counters(user_id, :diary_entries)
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :users, :diary_entries_count
|
||||
end
|
||||
end
|
|
@ -1006,7 +1006,8 @@ CREATE TABLE users (
|
|||
description_format format_enum DEFAULT 'html'::format_enum NOT NULL,
|
||||
image_fingerprint character varying(255),
|
||||
changesets_count integer DEFAULT 0 NOT NULL,
|
||||
traces_count integer DEFAULT 0 NOT NULL
|
||||
traces_count integer DEFAULT 0 NOT NULL,
|
||||
diary_entries_count integer DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
|
@ -2267,6 +2268,8 @@ INSERT INTO schema_migrations (version) VALUES ('20120404205604');
|
|||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20120808231205');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('20121005195010');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('21');
|
||||
|
||||
INSERT INTO schema_migrations (version) VALUES ('22');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue