修改新建topic界面

This commit is contained in:
fanqiang 2013-11-23 20:56:22 +08:00
parent 17cb97828d
commit 6e1913d00d
4 changed files with 25 additions and 10 deletions

View File

@ -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
@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 { redirect_to forum_memo_path(@memo.forum_id, @back_memo_id) }
format.json { render json: @memo.errors, status: :unprocessable_entity }
end
else
format.html { render action: "new" }
format.json { render json: @memo.errors, status: :unprocessable_entity }

View File

@ -0,0 +1,18 @@
<%= labelled_form_for(@memo, :url => forum_memos_path) do |f| %>
<% if @memo.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@memo.errors.count, "error") %> prohibited this memo from being saved:</h2>
<ul>
<% @memo.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="actions">
<p><%= f.text_field :subject, :required => true %></p>
<p><%= f.text_field :content, :required => true, :size => 80 %></p>
<%= f.submit %>
</div>
<% end %>

View File

@ -1,5 +1,5 @@
<h1>New memo</h1>
<%= render :partial => 'form' %>
<%= render :partial => 'memos/topic_form' %>
<%= link_to 'Back', forums_path(@forum) %>

View File

@ -6,7 +6,7 @@ class CreateMemos < ActiveRecord::Migration
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