myshixun中id转换

This commit is contained in:
huang 2017-04-26 10:19:04 +08:00
parent 02d5287449
commit c98d8cdf1d
6 changed files with 13 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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 可以测评的,正在测评的
# 如果都完成,则当前任务为最后一个任务

View File

@ -9,8 +9,6 @@ class Shixun < ActiveRecord::Base
has_many :myshixuns
# id 转换成 identifier
# 如果是整数就去ID否则就取login
# 含有特殊符号的则显示ID
def to_param
identifier
end

View File

@ -33,7 +33,7 @@
</li>
<li class="mb5 ml63">
<label class="fl">&nbsp;语言&nbsp;&nbsp;</label>
<%= 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;" %>
</li>
<li class="mb5 ml70">
<label >&nbsp;公开&nbsp;</label>

View File

@ -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