This commit is contained in:
fanqiang 2013-11-23 08:20:03 +08:00
parent 48650a2a91
commit c50c77a7ca
6 changed files with 111 additions and 4 deletions

View File

@ -15,6 +15,7 @@ class ForumsController < ApplicationController
# GET /forums/1.json
def show
@forum = Forum.find(params[:id])
@memos = @forum.topics
respond_to do |format|
format.html # show.html.erb

View File

@ -1,2 +1,46 @@
class MemosController < ApplicationController
def new
@memo = Memo.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @memo }
end
end
def show
@memo = Memo.find(params[:id])
@replies = @memo.replies
respond_to do |format|
format.html # show.html.erb
format.json { render json: @memo }
end
end
def create
@memo = Memo.new(params[:memo])
@memo.author_id = User.current.id
respond_to do |format|
if @memo.save
format.html { redirect_to @memo, notice: 'Memo was successfully created.' }
format.json { render json: @memo, status: :created, location: @memo }
else
format.html { render action: "new" }
format.json { render json: @memo.errors, status: :unprocessable_entity }
end
end
end
def destroy
@memo = Memo.find(params[:id])
@memo.destroy
respond_to do |format|
format.html { redirect_to memos_url }
format.json { head :no_content }
end
end
end

View File

@ -2,6 +2,7 @@ class Memo < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :forums
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
safe_attributes "author_id",
"subject",
"content",
@ -14,4 +15,8 @@ class Memo < ActiveRecord::Base
validates_presence_of :author_id, :content, :forum_id, :subject
validates_length_of :subject, maximum: 50
validates_length_of :content, maximum: 2048
def replies
Memo.where("parent_id = ?", id)
end
end

View File

@ -1,6 +1,27 @@
<p id="notice"><%= notice %></p>
<p><%= %></p>
<p><%= %></p>
<p id="notice">
<%= notice %>
</p>
<p>
<%= %>
</p>
<p>
<%= %>
</p>
<%= link_to 'Edit', edit_forum_path(@forum) %> |
<%= link_to 'Back', forums_path %>
<%= link_to 'new_topic', new_forum_memo_path(@forum) %>
<table>
<tr>
<th>subject</th>
<th>content</th>
<th>author</th>
</tr>
<% @memos.each do |memo| %>
<tr>
<td><%= link_to memo.subject, forum_memo_path(memo) %></td>
<td><%= memo.content %></td>
<td><%= memo.author %></td>
</tr>
<% end %>
</table>

View File

@ -0,0 +1,36 @@
<p id="notice">
<%= notice %>
</p>
<p>
<%= %>
</p>
<p>
<%= %>
</p>
<table>
<tr>
<th>subject</th>
<th>content</th>
<th>author</th>
</tr>
<tr>
<td><%= link_to @memo.subject, forum_memo_path(@memo) %></td>
<td><%= @memo.content %></td>
<td><%= @memo.author %></td>
</tr>
</table>
<table>
<tr>
<th>subject</th>
<th>content</th>
<th>author</th>
</tr>
<% @replies.each do |reply| %>
<tr>
<td><%= link_to reply.subject, forum_memo_path(reply) %></td>
<td><%= reply.content %></td>
<td><%= reply.author %></td>
</tr>
<% end %>
</table>