diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index d2e57e85f..c49bc2a40 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -168,7 +168,7 @@ class GamesController < ApplicationController def next_step render_403 if @game.status != 2 next_game = @game.next_game - next_game.update_attribute(:status, 0) if next_game.status == 3 + next_game.update_attributes(:status => 0, :open_time => Time.now) if next_game.status == 3 respond_to do |format| format.js{redirect_to myshixun_game_path(next_game, :myshixun_id => @myshixun.id)} diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 4e9dd4102..7e48c8c4e 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -81,7 +81,7 @@ class ShixunsController < ApplicationController # 之所以增加user_id是为了方便统计查询性能 challenges.each_with_index do |challenge, index| status = (index == 0 ? 0 : 3) - Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id) + Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, :open_time => Time.now) end else raise("网络异常,请稍后重试") diff --git a/app/models/game.rb b/app/models/game.rb index 9117941ba..9bff76d7e 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,7 +1,7 @@ class Game < ActiveRecord::Base # stauts 0: can exe 1:doing 2:successed 3:locked default_scope :order => 'created_at desc' - attr_accessible :myshixun_id, :user_id, :status, :final_score, :challenge_id + attr_accessible :myshixun_id, :user_id, :status, :final_score, :challenge_id, :open_time belongs_to :myshixun,:touch=> true belongs_to :user belongs_to :challenge diff --git a/app/views/games/show.js.erb b/app/views/games/show.js.erb index 4ddbeb86d..7029c2bd1 100644 --- a/app/views/games/show.js.erb +++ b/app/views/games/show.js.erb @@ -1,3 +1,3 @@ -$("#all_task_show").toggle(); +$("#all_task_show").hide(); $("#game_show_content").html('<%= escape_javascript(render :partial => 'games/game_show') %>'); $("#current_task_tab").attr('href','<%= myshixun_game_path(@myshixun.current_task, :myshixun_id => @myshixun) %>'); diff --git a/db/migrate/20170414023452_add_open_time_to_game.rb b/db/migrate/20170414023452_add_open_time_to_game.rb new file mode 100644 index 000000000..7f0318a12 --- /dev/null +++ b/db/migrate/20170414023452_add_open_time_to_game.rb @@ -0,0 +1,5 @@ +class AddOpenTimeToGame < ActiveRecord::Migration + def change + add_column :games, :open_time, :datetime + end +end diff --git a/db/migrate/20170414024741_update_open_time_to_game.rb b/db/migrate/20170414024741_update_open_time_to_game.rb new file mode 100644 index 000000000..a5df9d440 --- /dev/null +++ b/db/migrate/20170414024741_update_open_time_to_game.rb @@ -0,0 +1,10 @@ +class UpdateOpenTimeToGame < ActiveRecord::Migration + def up + Game.all.each do |game| + game.update_attribute(:open_time, game.created_at) + end + end + + def down + end +end