添加经验值功能
This commit is contained in:
parent
40765efec5
commit
be17994e7a
|
@ -214,6 +214,7 @@ class GamesController < ApplicationController
|
|||
game_passed_code(@game.id, game_challenge.try(:path), @myshixun.try(:gpid), 1)
|
||||
if !@game.answer_open && shixun.status > 1
|
||||
reward_grade(@game.user, @game.id, @game.class, game_challenge.score)
|
||||
reward_experience(@game.user, @game.id, @game.class, game_challenge.score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -128,6 +128,14 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
def reward_experience(user, container_id, container_type, score)
|
||||
experience = Experience.where(:user_id => user.id, :container_id => container_id, :container_type => container_type).first
|
||||
if experience.nil?
|
||||
user.update_column(:experience, (score.to_i + user.experience.to_i))
|
||||
Grade.create!(:user_id => user.id, :container_id => container_id, :container_type => container_type, :score => score)
|
||||
end
|
||||
end
|
||||
|
||||
# codeMirror语言转换
|
||||
def language_switch language
|
||||
case language
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
class Experience < ActiveRecord::Base
|
||||
attr_accessible :container_id, :container_type, :score, :user_id
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddExperienceToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :experience, :integer, :default => 0
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
class CreateExperiences < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :experiences do |t|
|
||||
t.integer :user_id
|
||||
t.integer :container_id
|
||||
t.string :container_type
|
||||
t.integer :score
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
FactoryGirl.define do
|
||||
factory :experience do
|
||||
user_id 1
|
||||
container_id 1
|
||||
container_type "MyString"
|
||||
score 1
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Experience, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue