记录用户流量行文

dev_aliyun
jingquan huang 5 years ago
parent fb1d58a97c
commit ef95c59e59

@ -29,6 +29,14 @@ module Mobile
requires :id, type: Integer, desc: "帖子ID"
end
get ':id' do
# 记录用户流量源
if params[:edu]
ip = request.host
ua = UserAgent.find_by_ip(ip)
unless ua
UserAgent.create(:key => params[:edu].strip, :ip => request.host)
end
end
MemosService.new.show params, current_user
end

@ -0,0 +1,3 @@
class UserAgent < ActiveRecord::Base
end

@ -0,0 +1,12 @@
class CreateUserAgents < ActiveRecord::Migration
def change
create_table :user_agents do |t|
t.string :type
t.string :key
t.string :ip
t.timestamps
end
add_index(:user_agents, :ip, :unique => true)
end
end

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :user_agent do
type 1
key "MyString"
ip "MyString"
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe UserAgent, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save