添加game开启时间,open_time数据迁移。index刷新显示隐藏

This commit is contained in:
huang 2017-04-14 10:58:25 +08:00
parent f0d20ad122
commit e351834fb1
6 changed files with 19 additions and 4 deletions

View File

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

View File

@ -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("网络异常,请稍后重试")

View File

@ -1,7 +1,7 @@
class Game < ActiveRecord::Base
# stauts 0: can exe 1doing 2successed 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

View File

@ -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) %>');

View File

@ -0,0 +1,5 @@
class AddOpenTimeToGame < ActiveRecord::Migration
def change
add_column :games, :open_time, :datetime
end
end

View File

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