# HG changeset patch # User Nattee Niparnan # Date 2015-09-14 10:29:39 # Node ID 7fdec87758d5563a9655593641f168534f2138c0 # Parent b75c92a947ffbd71a8d6a350f9ff823784a4c5e2 add heart_beat (grafted from baf0af002308b84f920a384166b4265c82124159) diff --git a/app/controllers/heartbeat_controller.rb b/app/controllers/heartbeat_controller.rb new file mode 100644 --- /dev/null +++ b/app/controllers/heartbeat_controller.rb @@ -0,0 +1,14 @@ +class HeartbeatController < ApplicationController + def edit + render layout: 'empty' + @user = User.find_by_login(params[:id]) + return unless @user + + hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first + if hb + hb.touch + else + HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip) + end + end +end diff --git a/app/models/heart_beat.rb b/app/models/heart_beat.rb new file mode 100644 --- /dev/null +++ b/app/models/heart_beat.rb @@ -0,0 +1,6 @@ +class HeartBeat < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :user + + #attr_accessible :ip_address +end diff --git a/app/views/heartbeat/edit.html.haml b/app/views/heartbeat/edit.html.haml new file mode 100644 --- /dev/null +++ b/app/views/heartbeat/edit.html.haml @@ -0,0 +1,1 @@ +OK diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -64,6 +64,8 @@ match 'tasks/view/:file.:ext' => 'tasks#view' match 'tasks/download/:id/:file.:ext' => 'tasks#download' + match 'heartbeat/:id/edit' => 'heartbeat#edit' + # See how all your routes lay out with "rake routes" # This is a legacy wild controller route that's not recommended for RESTful applications. diff --git a/db/migrate/20150914090545_create_heart_beats.rb b/db/migrate/20150914090545_create_heart_beats.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20150914090545_create_heart_beats.rb @@ -0,0 +1,10 @@ +class CreateHeartBeats < ActiveRecord::Migration + def change + create_table :heart_beats do |t| + t.column 'user_id',:integer + t.column 'ip_address',:string + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150827133841) do +ActiveRecord::Schema.define(:version => 20150914090545) do create_table "announcements", :force => true do |t| t.string "author" @@ -79,6 +79,13 @@ add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" + create_table "heart_beats", :force => true do |t| + t.integer "user_id" + t.string "ip_address" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "languages", :force => true do |t| t.string "name", :limit => 10 t.string "pretty_name" @@ -249,6 +256,7 @@ t.boolean "enabled", :default => true t.string "remark" t.string "last_ip" + t.string "section" end add_index "users", ["login"], :name => "index_users_on_login", :unique => true