This commit is contained in:
yanxd 2013-11-23 21:13:59 +08:00
parent 6e1913d00d
commit c6f4dbbafa
3 changed files with 11 additions and 9 deletions

View File

@ -10,7 +10,7 @@ class MemosController < ApplicationController
end
def show
@memo = Memo.find(params[:id])
@memo = Memo.find_by_id(params[:id])
@replies = @memo.replies
@mome_new = Memo.new
@ -26,16 +26,18 @@ class MemosController < ApplicationController
@memo.author_id = User.current.id
if @memo.parent_id
@back_memo_id ||= @memo.parent_id
@parent_memo = Memo.find_by_id(@memo.parent_id)
@parent_memo.replies_count += 1
end
respond_to do |format|
if @memo.save
@back_memo_id = @memo.id
@parent_memo.last_reply_id = @memo.id if @parent_memo
@parent_memo.save if @parent_memo
@back_memo_id = (@memo.parent_id.nil? ? @memo.id : @memo.parent_id)
if @parent_memo
@parent_memo.last_reply_id = @memo.id
@parent_memo.save
end
format.html { redirect_to forum_memo_path(@memo.forum_id, @back_memo_id), notice: 'Memo was successfully created.' }
format.json { render json: @memo, status: :created, location: @memo }
else

View File

@ -1,7 +1,7 @@
<!-- <p id="notice">
< %= notice %>
</p> -->
<ul class="lz" style="background:red" >
<ul class="lz" style="background:grey" >
<!-- <li class="title">title ==> <%= link_to @memo.subject, forum_memo_path(@memo) %></li>
<li class="content">content ==> <%= @memo.content %></li>
<li class="author">author ==> <%= @memo.author %></li>
@ -21,7 +21,7 @@
</ul>
<hr/>
<h3 class="comments"><%= l(:label_reply_plural) %> (<%= @replies.nil? ? 0 : @replies.size %>)</h3>
<div class="replies">
<% @replies.each do |reply| %>
@ -37,7 +37,7 @@
image_tag('edit.png'),
{:action => 'edit', :id => reply},
:title => l(:button_edit)
) if reply.editable_by?(User.current) %>
) if reply.destroyable_by?(User.current) %>
<%= link_to(
image_tag('delete.png'),
{:action => 'destroy', :id => reply},

View File

@ -439,7 +439,7 @@ ActiveRecord::Schema.define(:version => 20131122132942) do
t.string "subject", :null => false
t.text "content", :null => false
t.integer "author_id", :null => false
t.integer "replies_count"
t.integer "replies_count", :default => 0
t.integer "last_reply_id"
t.boolean "lock", :default => false
t.boolean "sticky", :default => false