Commit da8298ea authored by 神楽坂玲奈's avatar 神楽坂玲奈

比赛初步

parent 2612a11a
# 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/
// Place all the styles related to the matches controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the tournaments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
#encoding: UTF-8
class MatchesController < ApplicationController
layout 'ygo'
# GET /matches
# GET /matches.json
def index
@matches = Match.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @matches }
end
end
# GET /matches/1
# GET /matches/1.json
def show
@match = Match.find(params[:id])
@actions = [{"ygo战网" => users_path}, "比赛详情"]
respond_to do |format|
format.html # show.html.erb
format.json { render json: @match }
end
end
# GET /matches/new
# GET /matches/new.json
def new
@match = Match.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @match }
end
end
# GET /matches/1/edit
def edit
@match = Match.find(params[:id])
end
# POST /matches
# POST /matches.json
def create
@match = Match.new(params[:match])
respond_to do |format|
if @match.save
format.html { redirect_to @match, notice: 'Match was successfully created.' }
format.json { render json: @match, status: :created, location: @match }
else
format.html { render action: "new" }
format.json { render json: @match.errors, status: :unprocessable_entity }
end
end
end
# PUT /matches/1
# PUT /matches/1.json
def update
@match = Match.find(params[:id])
respond_to do |format|
if @match.update_attributes(params[:match])
format.html { redirect_to @match, notice: 'Match was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @match.errors, status: :unprocessable_entity }
end
end
end
# DELETE /matches/1
# DELETE /matches/1.json
def destroy
@match = Match.find(params[:id])
@match.destroy
respond_to do |format|
format.html { redirect_to matches_url }
format.json { head :no_content }
end
end
end
#encoding: UTF-8
class TournamentsController < ApplicationController
layout 'ygo'
# GET /tournaments
# GET /tournaments.json
def index
@tournaments = Tournament.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tournaments }
end
end
# GET /tournaments/1
# GET /tournaments/1.json
def show
@tournament = Tournament.find(params[:id])
@actions = [{"YGO战网" => users_path}, @tournament.name ]
respond_to do |format|
format.html # show.html.erb
format.json { render json: @tournament }
end
end
# GET /tournaments/new
# GET /tournaments/new.json
def new
@tournament = Tournament.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @tournament }
end
end
# GET /tournaments/1/edit
def edit
@tournament = Tournament.find(params[:id])
end
# POST /tournaments
# POST /tournaments.json
def create
@tournament = Tournament.new(params[:tournament])
respond_to do |format|
if @tournament.save
format.html { redirect_to @tournament, notice: 'Tournament was successfully created.' }
format.json { render json: @tournament, status: :created, location: @tournament }
else
format.html { render action: "new" }
format.json { render json: @tournament.errors, status: :unprocessable_entity }
end
end
end
# PUT /tournaments/1
# PUT /tournaments/1.json
def update
@tournament = Tournament.find(params[:id])
respond_to do |format|
if @tournament.update_attributes(params[:tournament])
format.html { redirect_to @tournament, notice: 'Tournament was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @tournament.errors, status: :unprocessable_entity }
end
end
end
# DELETE /tournaments/1
# DELETE /tournaments/1.json
def destroy
@tournament = Tournament.find(params[:id])
@tournament.destroy
respond_to do |format|
format.html { redirect_to tournaments_url }
format.json { head :no_content }
end
end
end
module MatchesHelper
end
module TournamentsHelper
end
class Match < ActiveRecord::Base
belongs_to :player1, :class_name => "User"
belongs_to :player2, :class_name => "User"
belongs_to :duel1, :class_name => "Duel"
belongs_to :duel2, :class_name => "Duel"
belongs_to :duel3, :class_name => "Duel"
belongs_to :tournament
#attr_accessible :player1_score, :player2_score, :round
end
class Tournament < ActiveRecord::Base
attr_accessible :location, :location_type, :name, :note
end
<style>
#boardheader h1{
background-color: black;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.6);
width:800px;
height:40px;
margin-top: 30px;
padding-left: 120px;
padding-top: 24px;
color: white;
font-size: 28px;
color: #ffffff;
position: relative;
font-size: 28px;
/* 背景透明 */
filter:alpha(opacity=60);
/*filter:alpha(opacity=60);
-moz-opacity:0.6;
opacity:0.6;
opacity:0.6;*/
}
#notice{
margin-left: 160px;
......@@ -23,6 +25,7 @@
#notice a{
color: gold;
}
#notice ol li{text-shadow:1px 1px 5px #000;}
#boardstats strong{
/*color: gold;*/
}
......@@ -37,7 +40,7 @@
color: white;
}
#boardstats{
font-size: 16px;
font-size: 16px;
color: white;
position: absolute;
right: 60px;
......@@ -47,7 +50,7 @@
<div id="wrap" class="wrap s_clear">
<article class="main content">
<header id="boardheader" class="s_clear" style="position:relative">
<div style="position: absolute; height: 100%">
<div style="position: absolute; height: 100%;text-shadow:1px 1px 5px #000;">
<h1><%= @board.name %></h1>
<div id="notice"><%= @board.notice.bbcode_to_html.html_safe %></div>
<p id="moderators">版主: <%=render @board.moderators %></p>
......
<%= form_for(@match) do |f| %>
<% if @match.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:</h2>
<ul>
<% @match.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :player1_id %><br />
<%= f.text_field :player1_id %>
</div>
<div class="field">
<%= f.label :player1_score %><br />
<%= f.number_field :player1_score %>
</div>
<div class="field">
<%= f.label :player2_id %><br />
<%= f.text_field :player2_id %>
</div>
<div class="field">
<%= f.label :player2_score %><br />
<%= f.number_field :player2_score %>
</div>
<div class="field">
<%= f.label :round %><br />
<%= f.number_field :round %>
</div>
<div class="field">
<%= f.label :duel1_id %><br />
<%= f.text_field :duel1_id %>
</div>
<div class="field">
<%= f.label :duel2_id %><br />
<%= f.text_field :duel2_id %>
</div>
<div class="field">
<%= f.label :duel3_id %><br />
<%= f.text_field :duel3_id %>
</div>
<div class="field">
<%= f.label :tournament %><br />
<%= f.select :tournament_id, Tournament.all.collect{|tournament|[tournament.name, tournament.id]} %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<h1>Editing match</h1>
<%= render 'form' %>
<%= link_to 'Show', @match %> |
<%= link_to 'Back', matches_path %>
<h1>Listing matches</h1>
<table>
<tr>
<th>Player1</th>
<th>Player1 score</th>
<th>Player2</th>
<th>Player2 score</th>
<th>Round</th>
<th>Duel1</th>
<th>Duel2</th>
<th>Duel3</th>
<th>Tournament</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @matches.each do |match| %>
<tr>
<td><%= match.player1 %></td>
<td><%= match.player1_score %></td>
<td><%= match.player2 %></td>
<td><%= match.player2_score %></td>
<td><%= match.round %></td>
<td><%= match.duel1 %></td>
<td><%= match.duel2 %></td>
<td><%= match.duel3 %></td>
<td><%= match.tournament %></td>
<td><%= link_to 'Show', match %></td>
<td><%= link_to 'Edit', edit_match_path(match) %></td>
<td><%= link_to 'Destroy', match, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Match', new_match_path %>
<h1>New match</h1>
<%= render 'form' %>
<%= link_to 'Back', matches_path %>
<p id="notice"><%= notice %></p>
<p>
<b>Player1:</b>
<%=link_to @match.player1.name, @match.player1 %>
</p>
<p>
<b>Player1 score:</b>
<%= @match.player1_score %>
</p>
<p>
<b>Player2:</b>
<%=link_to @match.player2.name, @match.player2 %>
</p>
<p>
<b>Player2 score:</b>
<%= @match.player2_score %>
</p>
<p>
<b>Round:</b>
<%= @match.round %>
</p>
<p>
<b>Duel1:</b>
<%=link_to @match.duel1 %>
</p>
<p>
<b>Duel2:</b>
<%=link_to @match.duel2 %>
</p>
<p>
<b>Duel3:</b>
<%=link_to @match.duel3 %>
</p>
<p>
<b>Tournament:</b>
<%=link_to @match.tournament.name, @match.tournament %>
</p>
<%= link_to 'Edit', edit_match_path(@match) %> |
<%= link_to 'Back', matches_path %>
......@@ -86,6 +86,7 @@
<div id="footer1">
<h2>其他服务</h2>
<a href="/api">API</a>
<a href="mailto:zh99998@gmail.com">联系作者</a>
</div>
<div id="footer2">
<h2>合作伙伴</h2>
......@@ -93,11 +94,8 @@
</div>
<div id="footer3">
<h2>版权申明</h2>
<a href="http://oapo.qzworld.net">
本作品的创作传播应遵循OAPO协议。
<img src="http://oapo.qzworld.net/images/icons/fee.png"></img>
<img src="http://oapo.qzworld.net/images/icons/use.png"></img>
</a>
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/"><img alt="知识共享许可协议" src="http://i.creativecommons.org/l/by-nc-sa/2.5/cn/88x31.png" /></a>
<a rel="license" href="http://www.gnu.org/licenses/gpl-3.0.html"><img alt="知识共享许可协议" src="http://gplv3.fsf.org/gplv3-88x31.png" /></a>
</div>
</footer>
</body>
\ No newline at end of file
<%= form_for(@tournament) do |f| %>
<% if @tournament.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@tournament.errors.count, "error") %> prohibited this tournament from being saved:</h2>
<ul>
<% @tournament.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :location_type %><br />
<%= f.text_field :location_type %>
</div>
<div class="field">
<%= f.label :location %><br />
<%= f.text_field :location %>
</div>
<div class="field">
<%= f.label :note %><br />
<%= f.text_area :note %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<h1>Editing tournament</h1>
<%= render 'form' %>
<%= link_to 'Show', @tournament %> |
<%= link_to 'Back', tournaments_path %>
<h1>Listing tournaments</h1>
<table>
<tr>
<th>Name</th>
<th>Location type</th>
<th>Location</th>
<th>Note</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @tournaments.each do |tournament| %>
<tr>
<td><%= tournament.name %></td>
<td><%= tournament.location_type %></td>
<td><%= tournament.location %></td>
<td><%= tournament.note %></td>
<td><%= link_to 'Show', tournament %></td>
<td><%= link_to 'Edit', edit_tournament_path(tournament) %></td>
<td><%= link_to 'Destroy', tournament, confirm: 'Are you sure?', method: :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Tournament', new_tournament_path %>
<h1>New tournament</h1>
<%= render 'form' %>
<%= link_to 'Back', tournaments_path %>
<p id="notice"><%= notice %></p>
<h2>
<%= @tournament.name %>
</h2>
<p>
<b>联系地点:</b>
<%= t 'tournament.location.' + @tournament.location_type %>
<% case @tournament.location_type %>
<% when "qun" %>
<a target="_blank" href="http://qun.qq.com/#jointhegroup/gid/<%= @tournament.location %>" alt="点击这里加入此群" title="点击这里加入此群"><%= @tournament.location %></a>
<% else %>
<%= @tournament.location %>
<% end %>
</p>
<p>
<b>备注:</b>
<%= @tournament.note %>
</p>
<p>
<b>时间:</b>
<%=l @tournament.updated_at.to_date %>
</p>
<%= link_to 'Edit', edit_tournament_path(@tournament) %> |
<%= link_to 'Back', tournaments_path %>
......@@ -373,4 +373,7 @@ zh-CN:
content: "正文"
submit: "提交"
private: "仅楼主可见"
anonymous: "匿名发帖"
\ No newline at end of file
anonymous: "匿名发帖"
tournament:
location:
qun: "QQ群"
\ No newline at end of file
MycardServerHttp::Application.routes.draw do
resources :matches
resources :tournaments
get "captcha/show"
resources :attachments
......
class CreateTournaments < ActiveRecord::Migration
def change
create_table :tournaments do |t|
t.string :name
t.string :location_type
t.string :location
t.text :note
t.timestamps
end
end
end
class CreateMatches < ActiveRecord::Migration
def change
create_table :matches do |t|
t.references :player1
t.integer :player1_score
t.references :player2
t.integer :player2_score
t.integer :round
t.references :duel1
t.references :duel2
t.references :duel3
t.references :tournament
t.timestamps
end
add_index :matches, :player1_id
add_index :matches, :player2_id
add_index :matches, :duel1_id
add_index :matches, :duel2_id
add_index :matches, :duel3_id
add_index :matches, :tournament_id
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120522232536) do
ActiveRecord::Schema.define(:version => 20120531032103) do
create_table "attachments", :force => true do |t|
t.string "data_file_name"
......@@ -127,6 +127,27 @@ ActiveRecord::Schema.define(:version => 20120522232536) do
t.datetime "updated_at", :null => false
end
create_table "matches", :force => true do |t|
t.integer "player1_id"
t.integer "player1_score"
t.integer "player2_id"
t.integer "player2_score"
t.integer "round"
t.integer "duel1_id"
t.integer "duel2_id"
t.integer "duel3_id"
t.integer "tournament_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "matches", ["duel1_id"], :name => "index_matches_on_duel1_id"
add_index "matches", ["duel2_id"], :name => "index_matches_on_duel2_id"
add_index "matches", ["duel3_id"], :name => "index_matches_on_duel3_id"
add_index "matches", ["player1_id"], :name => "index_matches_on_player1_id"
add_index "matches", ["player2_id"], :name => "index_matches_on_player2_id"
add_index "matches", ["tournament_id"], :name => "index_matches_on_tournament_id"
create_table "moderations", :force => true do |t|
t.integer "user_id"
t.integer "association_id"
......@@ -231,6 +252,15 @@ ActiveRecord::Schema.define(:version => 20120522232536) do
t.datetime "updated_at", :null => false
end
create_table "tournaments", :force => true do |t|
t.string "name"
t.string "location_type"
t.string "location"
t.text "note"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "name", :null => false
t.string "password"
......
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
player1:
player1_score: 1
player2:
player2_score: 1
round: 1
duel1:
duel2:
duel3:
tournament:
two:
player1:
player1_score: 1
player2:
player2_score: 1
round: 1
duel1:
duel2:
duel3:
tournament:
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
name: MyString
location_type: MyString
location: MyString
note: MyText
two:
name: MyString
location_type: MyString
location: MyString
note: MyText
require 'test_helper'
class MatchesControllerTest < ActionController::TestCase
setup do
@match = matches(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:matches)
end
test "should get new" do
get :new
assert_response :success
end
test "should create match" do
assert_difference('Match.count') do
post :create, match: { player1_score: @match.player1_score, player2_score: @match.player2_score, round: @match.round }
end
assert_redirected_to match_path(assigns(:match))
end
test "should show match" do
get :show, id: @match
assert_response :success
end
test "should get edit" do
get :edit, id: @match
assert_response :success
end
test "should update match" do
put :update, id: @match, match: { player1_score: @match.player1_score, player2_score: @match.player2_score, round: @match.round }
assert_redirected_to match_path(assigns(:match))
end
test "should destroy match" do
assert_difference('Match.count', -1) do
delete :destroy, id: @match
end
assert_redirected_to matches_path
end
end
require 'test_helper'
class TournamentsControllerTest < ActionController::TestCase
setup do
@tournament = tournaments(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:tournaments)
end
test "should get new" do
get :new
assert_response :success
end
test "should create tournament" do
assert_difference('Tournament.count') do
post :create, tournament: { location: @tournament.location, location_type: @tournament.location_type, name: @tournament.name, note: @tournament.note }
end
assert_redirected_to tournament_path(assigns(:tournament))
end
test "should show tournament" do
get :show, id: @tournament
assert_response :success
end
test "should get edit" do
get :edit, id: @tournament
assert_response :success
end
test "should update tournament" do
put :update, id: @tournament, tournament: { location: @tournament.location, location_type: @tournament.location_type, name: @tournament.name, note: @tournament.note }
assert_redirected_to tournament_path(assigns(:tournament))
end
test "should destroy tournament" do
assert_difference('Tournament.count', -1) do
delete :destroy, id: @tournament
end
assert_redirected_to tournaments_path
end
end
require 'test_helper'
class MatchesHelperTest < ActionView::TestCase
end
require 'test_helper'
class TournamentsHelperTest < ActionView::TestCase
end
require 'test_helper'
class MatchTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class TournamentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
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