修改数据库后修复bug

This commit is contained in:
fanqiang 2014-05-20 16:10:05 +08:00
parent 87a6dd4938
commit aed4b250a0
5 changed files with 21 additions and 9 deletions

View File

@ -37,7 +37,7 @@ class RelativeMemosController < ApplicationController
def show
pre_count = REPLIES_PER_PAGE
@memo = @memo.root # 取出楼主防止输入帖子id让回复作为主贴显示
# @memo = @memo.root # 取出楼主防止输入帖子id让回复作为主贴显示
@memo.update_column(:viewed_count_local, (@memo.viewed_count_local.to_i + 1))
page = params[:page]
@ -142,7 +142,7 @@ class RelativeMemosController < ApplicationController
def find_memo
return unless find_osp
@memo = @open_source_project.relative_memos.find(params[:id])
@memo = @open_source_project.topics.find(RelativeMemo.find(params[:id]).root.id)
rescue ActiveRecord::RecordNotFound
render_404
nil

View File

@ -12,7 +12,6 @@ class RelativeMemo < ActiveRecord::Base
has_many :no_uses, :as => :no_use, :dependent => :delete_all
acts_as_taggable
acts_as_attachable
validates_presence_of :subject
#validates :content, presence: true
@ -82,6 +81,11 @@ class RelativeMemo < ActiveRecord::Base
{ :include => :no_uses,
:conditions => ["#{NoUse.table_name}.user_id = ?", user_id] }
}
# 获取帖子的回复
def replies
memos = RelativeMemo.where("parent_id = ?", id)
end
def no_use_for?(user)
self.no_uses.each do |no_use|

View File

@ -1,7 +1,14 @@
class RelativeMemoToOpenSourceProject < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :open_source_project, :foreign_key => "osp_id"
belongs_to :relative_memo, :foreign_key => 'relative_memo_id'
belongs_to :topic, :class_name => 'RelativeMemo', :foreign_key => 'relative_memo_id'
has_many :no_uses, :as => :no_use, :dependent => :delete_all
validates_presence_of :osp_id, :relative_memo_id
scope :no_use_for, lambda { |user_id|
{:include => :no_uses,
:conditions => ["#{NoUse.table_name}.user_id = ?", user_id] }
}
end

View File

@ -13,11 +13,11 @@
<td>
<table width="630px" border="0">
<tr>
<td valign="top" width="500px" class="<%= topic.sticky ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>"><%= link_to h(topic.subject), open_source_project_relative_memo_path(topic.open_source_project, topic) %></td>
<td valign="top" width="500px" class="<%= topic.sticky ? 'sticky' : '' %> <%= topic.locked? ? 'locked' : '' %>"><%= link_to h(topic.subject), open_source_project_relative_memo_path(open_source_project, topic) %></td>
<td align="right" rowspan="3">
<table class="borad-count">
<tr>
<td align="center" class="borad-count-digit"><%= link_to (topic.replies_count), open_source_project_relative_memo_path(topic.open_source_project, topic) %></td>
<td align="center" class="borad-count-digit"><%= link_to (topic.replies_count), open_source_project_relative_memo_path(open_source_project, topic) %></td>
</tr>
<tr>
<td align="center">回答</td>
@ -26,7 +26,7 @@
<td align="right" rowspan="3">
<table class="borad-count">
<tr>
<td align="center" class="borad-count-digit"><%= link_to (topic.viewed_count_crawl+topic.viewed_count_local), open_source_project_relative_memo_path(topic.open_source_project, topic) %></td>
<td align="center" class="borad-count-digit"><%= link_to (topic.viewed_count_crawl+topic.viewed_count_local), open_source_project_relative_memo_path(open_source_project, topic) %></td>
</tr>
<tr>
<td align="center">浏览</td>
@ -43,7 +43,8 @@
</tr>
<tr>
<td align="left" colspan="2" ><span class="font_lighter">帖子来源:<%= link_to topic.url, topic.url%> </span></td>
<td align="left"><%= no_use_link(topic, User.current) %> </td>
<% relation_memo = RelativeMemoToOpenSourceProject.where("osp_id = ? and relative_memo_id = ?", open_source_project.id, topic.id).first %>
<td align="left"><%= no_use_link(relation_memo, User.current) %> </td>
</tr>
<tr>
<td align="left" colspan="2"> <%= image_tag( "/images/sidebar/tags.png") %>

View File

@ -51,4 +51,4 @@
:title => l(:button_delete)
) if @forum.destroyable_by?(User.current) %>
</div>
<%= render :partial => 'open_source_projects/show_topics', :locals => {:memos => @memos} %>
<%= render :partial => 'open_source_projects/show_topics', :locals => {:memos => @memos, :open_source_project => @open_source_project} %>