diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 82ac7480b..fdb71892b 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -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 diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 7b55a1761..7ba5aec43 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -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 diff --git a/app/models/memo.rb b/app/models/memo.rb index 3668182b0..efe521f1c 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -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 diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 63ac98bbf..60ded0524 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -1,6 +1,27 @@ -
<%= notice %>
-<%= %>
-<%= %>
++ <%= notice %> +
++ <%= %> +
++ <%= %> +
<%= link_to 'Edit', edit_forum_path(@forum) %> | <%= link_to 'Back', forums_path %> +<%= link_to 'new_topic', new_forum_memo_path(@forum) %> +subject | +content | +author | +
---|---|---|
<%= link_to memo.subject, forum_memo_path(memo) %> | +<%= memo.content %> | +<%= memo.author %> | +
+ <%= notice %> +
++ <%= %> +
++ <%= %> +
+subject | +content | +author | +
---|---|---|
<%= link_to @memo.subject, forum_memo_path(@memo) %> | +<%= @memo.content %> | +<%= @memo.author %> | +
subject | +content | +author | +
---|---|---|
<%= link_to reply.subject, forum_memo_path(reply) %> | +<%= reply.content %> | +<%= reply.author %> | +