From c98d8cdf1db4880d0bbc780cdad3db2c9a5efe33 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 26 Apr 2017 10:19:04 +0800 Subject: [PATCH] =?UTF-8?q?myshixun=E4=B8=ADid=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- app/controllers/myshixuns_controller.rb | 2 +- app/models/myshixun.rb | 5 +++++ app/models/shixun.rb | 2 -- app/views/shixuns/_form.html.erb | 2 +- db/migrate/20170425093133_sync_identifier_to_myshixun.rb | 8 +++++--- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 2b9ec4631..3bbfa1705 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -203,7 +203,7 @@ class GamesController < ApplicationController next_game = @game.next_game next_game.update_attributes(:status => 0, :open_time => Time.now) if next_game.status == 3 - redirect_to myshixun_game_path(next_game, :myshixun_id => @myshixun.id) + redirect_to myshixun_game_path(next_game, :myshixun_id => @myshixun) end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index fe0dadbad..eb1c62a8a 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -51,7 +51,7 @@ class MyshixunsController < ApplicationController private # Find myshixun of id params[:id] def find_myshixun - @myshixun = Myshixun.find(params[:id]) + @myshixun = Myshixun.find_by_identifier(params[:id]) rescue ActiveRecord::RecordNotFound render_404 end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index ce0e08623..cd7a035a3 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -6,6 +6,11 @@ class Myshixun < ActiveRecord::Base has_many :games, :dependent => :destroy, :order => "games.id ASC" belongs_to :shixun + # id 转换成 identifier + def to_param + identifier + end + # 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录) # status:0 可以测评的,正在测评的 # 如果都完成,则当前任务为最后一个任务 diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 9cd7c320a..f071f23dc 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -9,8 +9,6 @@ class Shixun < ActiveRecord::Base has_many :myshixuns # id 转换成 identifier - # 如果是整数就去ID,否则就取login - # 含有特殊符号的则显示ID def to_param identifier end diff --git a/app/views/shixuns/_form.html.erb b/app/views/shixuns/_form.html.erb index fc1ce97f8..b8a2176d1 100644 --- a/app/views/shixuns/_form.html.erb +++ b/app/views/shixuns/_form.html.erb @@ -33,7 +33,7 @@
  • - <%= select_tag :language, options_for_select(["Java","C","C++","Python","Ruby"], "Java"), :id => 'shixun[language]', :class => "ml5", :style => "height: 28px;" %> + <%= select_tag :language, options_for_select(["Java","C","C++","Python","Ruby","Mysql-Java"], "Java"), :id => 'shixun[language]', :class => "ml5", :style => "height: 28px;" %>
  • diff --git a/db/migrate/20170425093133_sync_identifier_to_myshixun.rb b/db/migrate/20170425093133_sync_identifier_to_myshixun.rb index b927c6690..c8daaf31d 100644 --- a/db/migrate/20170425093133_sync_identifier_to_myshixun.rb +++ b/db/migrate/20170425093133_sync_identifier_to_myshixun.rb @@ -1,7 +1,9 @@ class SyncIdentifierToMyshixun < ActiveRecord::Migration def up - end - - def down + myshixuns = Myshixun.all + myshixuns.each do |myshixun| + identifier = myshixun.shixun.try(:identifier) + myshixun.update_attribute(:identifier, identifier) + end end end