diff --git a/app/models/experience.rb b/app/models/experience.rb
index 1892f2f13..3f2649587 100644
--- a/app/models/experience.rb
+++ b/app/models/experience.rb
@@ -1,5 +1,5 @@
class Experience < ActiveRecord::Base
- attr_accessible :container_id, :container_type, :score, :user_id
+ attr_accessible :container_id, :container_type, :score, :user_id, :created_at, :updated_at
belongs_to :user
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 1580df643..1a9152d37 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -315,9 +315,7 @@ class User < Principal
end
}
def challenge_tags
- shixuns = Shixun.where(:id => Myshixun.where(:user_id => self.id).map(&:shixun_id), :status => [2,3])
- myshixuns = Myshixun.where(:user_id => self.id, :shixun_id => shixuns.map(&:id))
- games = self.games.where(:myshixun_id => myshixuns.map(&:id), :status => 2)
+ games = self.games.where(:id => self.experiences.map(&:container_id), :status => 2)
challenge_tags = ChallengeTag.where(:challenge_id => games.map(&:challenge_id))
end
diff --git a/app/views/users/_user_experience_content.html.erb b/app/views/users/_user_experience_content.html.erb
index 94031e0df..189fb046f 100644
--- a/app/views/users/_user_experience_content.html.erb
+++ b/app/views/users/_user_experience_content.html.erb
@@ -19,7 +19,7 @@
闯关 |
+ <%= exp.score %> |
<% game = Game.where(:id => exp.container_id).first %>
- <%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "" %> |
+ <%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "--" %> |
<%= format_time exp.created_at %> |
<% end %>
diff --git a/app/views/users/_user_grade_content.html.erb b/app/views/users/_user_grade_content.html.erb
index 36a0419a0..90cc104da 100644
--- a/app/views/users/_user_grade_content.html.erb
+++ b/app/views/users/_user_grade_content.html.erb
@@ -33,12 +33,12 @@
查看参考答案 |
- <%= grade.score.abs %> |
<% game = Game.where(:id => grade.container_id).first %>
- <%= game ? "查看实训“#{game.challenge.shixun.name}”第#{game.challenge.position}关的参考答案消耗的金币" : "" %> |
+ <%= game ? "查看实训“#{game.challenge.shixun.name}”第#{game.challenge.position}关的参考答案消耗的金币" : "--" %> |
<% when 'Game' %>
闯关 |
+ <%= grade.score %> |
<% game = Game.where(:id => grade.container_id).first %>
- <%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "" %> |
+ <%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的奖励" : "--" %> |
<% end %>
<%= format_time grade.created_at %> |
diff --git a/app/views/users/_user_tag_content.html.erb b/app/views/users/_user_tag_content.html.erb
index b3fcca569..5d5d4a723 100644
--- a/app/views/users/_user_tag_content.html.erb
+++ b/app/views/users/_user_tag_content.html.erb
@@ -15,13 +15,16 @@
<% @user_tags.each do |tag| %>
-
- | 闯关 |
- <% game = Game.where(:id => tag.container_id).first %>
- + 标签:<%= game ? game.challenge.challenge_tags.map(&:name).join("、") : "" %> |
- <%= game ? "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的标签" : "" %> |
- <%= format_time tag.created_at %> |
-
+ <% game = Game.where(:id => tag.container_id).first %>
+ <% if game && game.challenge.challenge_tags.count > 0 %>
+
+ | 闯关 |
+ <% game = Game.where(:id => tag.container_id).first %>
+ + 标签:<%= game ? game.challenge.challenge_tags.map(&:name).join("、") : "" %> |
+ <%= "通过实训“#{game.challenge.shixun.name}”的第#{game.challenge.position}关获得的标签" %> |
+ <%= format_time tag.created_at %> |
+
+ <% end %>
<% end %>
diff --git a/db/migrate/20170810012934_migrate_grade_exp.rb b/db/migrate/20170810012934_migrate_grade_exp.rb
index b08589a8a..705e408ec 100644
--- a/db/migrate/20170810012934_migrate_grade_exp.rb
+++ b/db/migrate/20170810012934_migrate_grade_exp.rb
@@ -1,14 +1,12 @@
class MigrateGradeExp < ActiveRecord::Migration
def up
- Grade.where(:container_type => "--- !ruby/class 'Game'").update_all(:container_type => 'Game')
- Experience.where(:container_type => "--- !ruby/class 'Game'").update_all(:container_type => 'Game')
-
- count = Grade.where(:container_type => "Game") / 30 + 2
+ count = Grade.where(:container_type => "Game").count / 30 + 2
transaction do
for i in 1 .. count do
Grade.where(:container_type => "Game").page(i).per(30).each do |score|
if Experience.where(:container_type => "Game", :container_id => score.container_id).blank?
- Experience.create!(:user_id => score.user_id, :container_id => score.container_id, :container_type => "Game", :score => score.score, :created_at => score.created_at, :updated_at => score.updated_at)
+ exp = Experience.create!(:user_id => score.user_id, :container_id => score.container_id, :container_type => "Game", :score => score.score, :created_at => score.created_at, :updated_at => score.updated_at)
+ exp.user.update_column(:experience, (exp.score.to_i + exp.user.experience.to_i))
end
end
end