From 6e1913d00db3f2fc4de80a7339f2b4f94797a5d9 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Sat, 23 Nov 2013 20:56:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E5=BB=BAtopic?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/memos_controller.rb | 13 +++++-------- app/views/memos/_topic_form.html.erb | 18 ++++++++++++++++++ app/views/memos/new.html.erb | 2 +- db/migrate/20131122132942_create_memos.rb | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 app/views/memos/_topic_form.html.erb diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 101ae69e2..4453d5f5e 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -22,8 +22,8 @@ class MemosController < ApplicationController def create @memo = Memo.new(params[:memo]) + @memo.forum_id = params[:forum_id] @memo.author_id = User.current.id - @back_memo_id = @memo.id if @memo.parent_id @back_memo_id ||= @memo.parent_id @@ -33,14 +33,11 @@ class MemosController < ApplicationController respond_to do |format| if @memo.save + @back_memo_id = @memo.id @parent_memo.last_reply_id = @memo.id if @parent_memo - if @parent_memo.save - 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 - format.html { redirect_to forum_memo_path(@memo.forum_id, @back_memo_id) } - format.json { render json: @memo.errors, status: :unprocessable_entity } - end + @parent_memo.save if @parent_memo + 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 format.html { render action: "new" } format.json { render json: @memo.errors, status: :unprocessable_entity } diff --git a/app/views/memos/_topic_form.html.erb b/app/views/memos/_topic_form.html.erb new file mode 100644 index 000000000..2cc5fbcf1 --- /dev/null +++ b/app/views/memos/_topic_form.html.erb @@ -0,0 +1,18 @@ +<%= labelled_form_for(@memo, :url => forum_memos_path) do |f| %> + <% if @memo.errors.any? %> +
<%= f.text_field :subject, :required => true %>
+<%= f.text_field :content, :required => true, :size => 80 %>
+ <%= f.submit %> +