Commit 36d7a8cf authored by 神楽坂玲奈's avatar 神楽坂玲奈

附件,发帖表单整理

parent 79f642db
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
//= require jquery.markitup
//= require jquery.markitup.set
\ No newline at end of file
// Place all the styles related to the attachments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
} }
.markItUp { .markItUp {
width:700px; width:700px;
height:201px;
margin:5px 0 5px 0; margin:5px 0 5px 0;
padding:5px; padding:5px;
box-shadow:0 0 5px #8e8e8e; box-shadow:0 0 5px #8e8e8e;
...@@ -30,7 +31,7 @@ ...@@ -30,7 +31,7 @@
.markItUpEditor { .markItUpEditor {
font:12px 'Courier New', Courier, monospace; font:12px 'Courier New', Courier, monospace;
border:0px; border:0px;
height:320px; height:160px;
clear:both; clear:both;
line-height:18px; line-height:18px;
overflow:auto; overflow:auto;
......
// Place all the styles related to the cards controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
//= require markitup
//= require markitup.set
\ No newline at end of file
class AttachmentsController < ApplicationController
# GET /attachments
# GET /attachments.json
def index
@attachments = Attachment.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @attachments }
end
end
# GET /attachments/1
# GET /attachments/1.json
def show
@attachment = Attachment.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @attachment }
end
end
# GET /attachments/new
# GET /attachments/new.json
def new
@attachment = Attachment.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @attachment }
end
end
# GET /attachments/1/edit
def edit
@attachment = Attachment.find(params[:id])
end
# POST /attachments
# POST /attachments.json
def create
@attachment = Attachment.new(params[:attachment])
respond_to do |format|
if @attachment.save
format.html { redirect_to @attachment, notice: 'Attachment was successfully created.' }
format.json { render json: @attachment, status: :created, location: @attachment }
else
format.html { render action: "new" }
format.json { render json: @attachment.errors, status: :unprocessable_entity }
end
end
end
# PUT /attachments/1
# PUT /attachments/1.json
def update
@attachment = Attachment.find(params[:id])
respond_to do |format|
if @attachment.update_attributes(params[:attachment])
format.html { redirect_to @attachment, notice: 'Attachment was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @attachment.errors, status: :unprocessable_entity }
end
end
end
# DELETE /attachments/1
# DELETE /attachments/1.json
def destroy
@attachment = Attachment.find(params[:id])
@attachment.destroy
respond_to do |format|
format.html { redirect_to attachments_url }
format.json { head :no_content }
end
end
end
class BoardsController < ApplicationController class BoardsController < ApplicationController
#ApplicationHelper::addon_header.push "zh_header"
#ApplicationHelper::addon_top.push "zh_top"
#ApplicationHelper::addon_footer.push "zh_footer"
# GET /boards # GET /boards
# GET /boards.xml # GET /boards.xml
def index def index
...@@ -21,7 +18,14 @@ class BoardsController < ApplicationController ...@@ -21,7 +18,14 @@ class BoardsController < ApplicationController
@actions = [{Board.human_attribute_name(:index) => boards_path}, @board] @actions = [{Board.human_attribute_name(:index) => boards_path}, @board]
@actions = [@board] @actions = [@board]
order = params[:order].blank? ? 'displayorder DESC, id DESC' : params[:order] order = params[:order].blank? ? 'displayorder DESC, id DESC' : params[:order]
@topics = @board.topics.page(params[:page]).order(order) @topics = @board.topics.page(params[:page]).order(order)
@topic = Topic.new #快速发帖
@topic.category_id = @board.id
@topic.category_type = :board
@topic.posts.build.attachments.build
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
format.xml { render :xml => params[:page] && !params[:page].empty? ? @topics : @board} format.xml { render :xml => params[:page] && !params[:page].empty? ? @topics : @board}
......
...@@ -32,6 +32,8 @@ class PostsController < ApplicationController ...@@ -32,6 +32,8 @@ class PostsController < ApplicationController
return render :text => "Topic not found or locked." return render :text => "Topic not found or locked."
end end
@post = Post.new @post = Post.new
@post.attachments.build
@post.attachments.build
@actions = [@topic, :reply] @actions = [@topic, :reply]
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
...@@ -42,6 +44,7 @@ class PostsController < ApplicationController ...@@ -42,6 +44,7 @@ class PostsController < ApplicationController
# GET /posts/1/edit # GET /posts/1/edit
def edit def edit
@post = Post.find(params[:id]) @post = Post.find(params[:id])
@post.attachments.build
@actions = [@post, :edit] @actions = [@post, :edit]
end end
......
...@@ -51,6 +51,9 @@ class TopicsController < ApplicationController ...@@ -51,6 +51,9 @@ class TopicsController < ApplicationController
@topic.update_attribute(:viewnum, @topic.viewnum + 1) @topic.update_attribute(:viewnum, @topic.viewnum + 1)
@current_user.update_attribute(:viewnum, @current_user.viewnum + 1) @current_user.update_attribute(:viewnum, @current_user.viewnum + 1)
@post = Post.new(topic: @topic)
@post.attachments.build
respond_to do |format| respond_to do |format|
format.html # show.html.erb format.html # show.html.erb
format.xml { render :xml => params[:page] && !params[:page].empty? ? @posts : @topic } format.xml { render :xml => params[:page] && !params[:page].empty? ? @posts : @topic }
...@@ -87,13 +90,15 @@ class TopicsController < ApplicationController ...@@ -87,13 +90,15 @@ class TopicsController < ApplicationController
@topic.user = @current_user @topic.user = @current_user
@topic.displayorder = 0 @topic.displayorder = 0
@post = Post.new(params[:post]) @topic.posts.first.displayorder = 1
@post.displayorder = 1 @topic.posts.first.user = @current_user
@post.topic = @topic #@post = Post.new(params[:post])
@post.user = @current_user #@post.displayorder = 1
#@post.topic = @topic
#@post.user = @current_user
respond_to do |format| respond_to do |format|
if @topic.save && @post.save if @topic.save
format.html { redirect_to(@topic, :notice => 'Topic was successfully created.') } format.html { redirect_to(@topic, :notice => 'Topic was successfully created.') }
format.xml { render :xml => @topic, :status => :created, :location => @topic } format.xml { render :xml => @topic, :status => :created, :location => @topic }
else else
......
module AttachmentsHelper
end
class Attachment < ActiveRecord::Base
belongs_to :post
has_attached_file :data
end
...@@ -2,6 +2,8 @@ class Post < ActiveRecord::Base ...@@ -2,6 +2,8 @@ class Post < ActiveRecord::Base
belongs_to :topic belongs_to :topic
belongs_to :user belongs_to :user
has_many :comments has_many :comments
has_many :attachments
accepts_nested_attributes_for :attachments
def user def user
super || User::Guest super || User::Guest
end end
......
...@@ -3,6 +3,7 @@ class Topic < ActiveRecord::Base ...@@ -3,6 +3,7 @@ class Topic < ActiveRecord::Base
#belongs_to :type #belongs_to :type
belongs_to :board, :foreign_key => :category_id belongs_to :board, :foreign_key => :category_id
has_many :posts has_many :posts
accepts_nested_attributes_for :posts
default_scope where(:deleted => false) default_scope where(:deleted => false)
self.per_page = 20 self.per_page = 20
......
<%= form_for(@attachment) do |f| %>
<% if @attachment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@attachment.errors.count, "error") %> prohibited this attachment from being saved:</h2>
<ul>
<% @attachment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :data_file_name %><br />
<%= f.text_field :data_file_name %>
</div>
<div class="field">
<%= f.label :data_content_type %><br />
<%= f.text_field :data_content_type %>
</div>
<div class="field">
<%= f.label :data_file_size %><br />
<%= f.number_field :data_file_size %>
</div>
<div class="field">
<%= f.label :data_updated_at %><br />
<%= f.datetime_select :data_updated_at %>
</div>
<div class="field">
<%= f.label :post_id %><br />
<%= f.number_field :post_id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<h1>Editing attachment</h1>
<%= render 'form' %>
<%= link_to 'Show', @attachment %> |
<%= link_to 'Back', attachments_path %>
<h1>Listing attachments</h1>
<table>
<tr>
<th>Data file name</th>
<th>Data content type</th>
<th>Data file size</th>
<th>Data updated at</th>
<th>Post</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @attachments.each do |attachment| %>
<tr>
<td><%= attachment.data_file_name %></td>
<td><%= attachment.data_content_type %></td>
<td><%= attachment.data_file_size %></td>
<td><%= attachment.data_updated_at %></td>
<td><%= attachment.post_id %></td>
<td><%= link_to 'Show', attachment %></td>
<td><%= link_to 'Edit', edit_attachment_path(attachment) %></td>
<td><%= link_to 'Destroy', attachment, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Attachment', new_attachment_path %>
<h1>New attachment</h1>
<%= render 'form' %>
<%= link_to 'Back', attachments_path %>
<p id="notice"><%= notice %></p>
<p>
<b>Data file name:</b>
<%= @attachment.data_file_name %>
</p>
<p>
<b>Data content type:</b>
<%= @attachment.data_content_type %>
</p>
<p>
<b>Data file size:</b>
<%= @attachment.data_file_size %>
</p>
<p>
<b>Data updated at:</b>
<%= @attachment.data_updated_at %>
</p>
<p>
<b>Post:</b>
<%= @attachment.post_id %>
</p>
<%= link_to 'Edit', edit_attachment_path(@attachment) %> |
<%= link_to 'Back', attachments_path %>
This diff is collapsed.
<%= form_for(@post) do |f| %> <%= form_for(@post, :html => { :multipart => true }) do |f| %>
<% if @post.errors.any? %> <% if @post.errors.any? %>
<div id="error_explanation"> <div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2> <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul> <ul>
<% @post.errors.full_messages.each do |msg| %> <% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li> <li><%= msg %></li>
<% end %> <% end %>
</ul> </ul>
</div> </div>
<% end %> <% end %>
<div class="field"> <!--<div class="field">
<%= f.label :topic %><br /> <%= f.label :topic %><br />
<%= f.text_field :topic %> <%= f.text_field :topic %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :user %><br /> <%= f.label :user %><br />
<%= f.text_field :user %> <%= f.text_field :user %>
</div> </div>-->
<div class="field"> <div class="field">
<%= f.label :content %><br /> <%= f.label :content %><br />
<%= f.text_area :content %> <%= f.text_area :content, :id => :fastpostmessage %>
</div> </div>
<div class="field"> <script type="text/javascript">
<%= f.label :displayorder %><br /> $(document).ready(function() {
<%= f.text_field :displayorder %> $('#fastpostmessage').markItUp(mySettings);
});
</script>
<!--<div class="field">
<%= f.label :displayorder %><br />
<%= f.text_field :displayorder %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :readperm %><br /> <%= f.label :readperm %><br />
<%= f.text_field :readperm %> <%= f.text_field :readperm %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :private %><br /> <%= f.label :private %><br />
<%= f.check_box :private %> <%= f.check_box :private %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :anonymous %><br /> <%= f.label :anonymous %><br />
<%= f.check_box :anonymous %> <%= f.check_box :anonymous %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :ubb %><br /> <%= f.label :ubb %><br />
<%= f.check_box :ubb %> <%= f.check_box :ubb %>
</div> </div>
<div class="field"> <div class="field">
<%= f.label :html %><br /> <%= f.label :html %><br />
<%= f.check_box :html %> <%= f.check_box :html %>
</div> </div>-->
<%= f.label "附件" %><br />
<%= f.fields_for :attachments do |attachment_form| %>
<div class="asset field">
<% if attachment_form.object.data.exists? %>
<%= attachment_form.object.data.original_filename %>
<% else %>
<%= attachment_form.file_field :data %>
<% end %>
</div>
<% end %>
<div class="actions"> <div class="actions">
<%= f.submit %> <%= f.submit %>
</div> </div>
......
...@@ -52,7 +52,19 @@ ...@@ -52,7 +52,19 @@
<div class="t_msgfontfix"> <div class="t_msgfontfix">
<table cellspacing="0" cellpadding="0"><tbody><tr><td class="t_msgfont" id="postmessage_751931"><%= post.content.bbcode_to_html.html_safe %> </td></tr></tbody></table> <table cellspacing="0" cellpadding="0"><tbody><tr><td class="t_msgfont" id="postmessage_751931"><%= post.content.bbcode_to_html.html_safe %> </td></tr></tbody></table>
</div> </div>
<% if !post.attachments.empty? %>
<p>
<b><%= post.attachments.size %> 个附件:</b>
<ul>
<% post.attachments.each do |attachment| %>
<li><%= link_to attachment.data.original_filename, attachment.data.url %></li>
<% if attachment.data.content_type[0,5] == "image" %>
<%= image_tag attachment.data.url %>
<% end %>
<% end %>
</ul>
</p>
<% end %>
<div id="post_rate_div_751931"></div> <div id="post_rate_div_751931"></div>
</div> </div>
......
<%= form_for(@post) do |f| %> <h1>Editing post</h1>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul> <%= render 'form' %>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<!--<div class="field"> <%= link_to 'Show', @post %> |
<%= f.label :topic %><br /> <%= link_to 'Back', posts_path %>
<%= f.text_field :topic %>
</div>-->
<div class="field">
<%= render 'topics/editor', :content => @post.content %>
</div>
<div class="field">
<%= f.label t 'post.private' %><br />
<%= f.check_box :private %>
</div>
<div class="field">
<%= f.label t 'post.anonymous' %><br />
<%= f.check_box :anonymous %>
</div>
<!--<div class="field">
<%= f.label :ubb %><br />
<%= f.check_box :ubb %>
</div>
<div class="field">
<%= f.label :html %><br />
<%= f.check_box :html %>
</div>-->
<div class="actions">
<%= f.submit t 'post.submit' %>
</div>
<% end %>
This diff is collapsed.
...@@ -259,6 +259,8 @@ zh-CN: ...@@ -259,6 +259,8 @@ zh-CN:
top_traps: "热门陷阱" top_traps: "热门陷阱"
board: board:
index: "论坛" index: "论坛"
post:
attachments: "附件"
mycard: mycard:
download: "立即下载" download: "立即下载"
battlenet: "YGO战网" battlenet: "YGO战网"
......
MycardServerHttp::Application.routes.draw do MycardServerHttp::Application.routes.draw do
resources :attachments
resources :moderators resources :moderators
resources :servers resources :servers
......
class CreateAttachments < ActiveRecord::Migration
def change
create_table :attachments do |t|
t.string :data_file_name
t.string :data_content_type
t.integer :data_file_size
t.datetime :data_updated_at
t.integer :post_id
t.timestamps
end
end
end
...@@ -11,7 +11,17 @@ ...@@ -11,7 +11,17 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120510085131) do ActiveRecord::Schema.define(:version => 20120518234415) do
create_table "attachments", :force => true do |t|
t.string "data_file_name"
t.string "data_content_type"
t.integer "data_file_size"
t.datetime "data_updated_at"
t.integer "post_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "boards", :force => true do |t| create_table "boards", :force => true do |t|
t.string "name", :default => "", :null => false t.string "name", :default => "", :null => false
...@@ -76,8 +86,11 @@ ActiveRecord::Schema.define(:version => 20120510085131) do ...@@ -76,8 +86,11 @@ ActiveRecord::Schema.define(:version => 20120510085131) do
t.string "replay" t.string "replay"
t.integer "user1_credits" t.integer "user1_credits"
t.integer "user2_credits" t.integer "user2_credits"
t.datetime "created_at", :null => false t.integer "version"
t.datetime "updated_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "user1_public", :default => true, :null => false
t.boolean "user2_public", :default => true, :null => false
end end
add_index "duels", ["user1_id"], :name => "index_duels_on_user1_id" add_index "duels", ["user1_id"], :name => "index_duels_on_user1_id"
...@@ -195,16 +208,6 @@ ActiveRecord::Schema.define(:version => 20120510085131) do ...@@ -195,16 +208,6 @@ ActiveRecord::Schema.define(:version => 20120510085131) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
create_table "sessions", :force => true do |t|
t.string "session_id", :null => false
t.text "data"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
create_table "settings", :primary_key => "name", :force => true do |t| create_table "settings", :primary_key => "name", :force => true do |t|
t.text "value" t.text "value"
end end
...@@ -231,7 +234,7 @@ ActiveRecord::Schema.define(:version => 20120510085131) do ...@@ -231,7 +234,7 @@ ActiveRecord::Schema.define(:version => 20120510085131) do
create_table "users", :force => true do |t| create_table "users", :force => true do |t|
t.string "name", :null => false t.string "name", :null => false
t.string "password" t.string "password"
t.string "email" t.string "email", :default => "", :null => false
t.string "nickname", :default => "", :null => false t.string "nickname", :default => "", :null => false
t.text "signature" t.text "signature"
t.integer "credits", :default => 0, :null => false t.integer "credits", :default => 0, :null => false
......
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
data_file_name: MyString
data_content_type: MyString
data_file_size: 1
data_updated_at: 2012-05-19 07:44:15
post_id: 1
two:
data_file_name: MyString
data_content_type: MyString
data_file_size: 1
data_updated_at: 2012-05-19 07:44:15
post_id: 1
require 'test_helper'
class AttachmentsControllerTest < ActionController::TestCase
setup do
@attachment = attachments(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:attachments)
end
test "should get new" do
get :new
assert_response :success
end
test "should create attachment" do
assert_difference('Attachment.count') do
post :create, attachment: @attachment.attributes
end
assert_redirected_to attachment_path(assigns(:attachment))
end
test "should show attachment" do
get :show, id: @attachment
assert_response :success
end
test "should get edit" do
get :edit, id: @attachment
assert_response :success
end
test "should update attachment" do
put :update, id: @attachment, attachment: @attachment.attributes
assert_redirected_to attachment_path(assigns(:attachment))
end
test "should destroy attachment" do
assert_difference('Attachment.count', -1) do
delete :destroy, id: @attachment
end
assert_redirected_to attachments_path
end
end
require 'test_helper'
class AttachmentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class AttachmentsHelperTest < ActionView::TestCase
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment