!!! 以下都是 ben7th 的临时记录,请勿参考
source 'https://gems.ruby-china.org'
development:
clients:
default:
database: im_core_development
hosts:
- localhost:27017
test:
clients:
default:
database: im_core_test
hosts:
- localhost:27017
options:
read:
mode: :primary
max_pool_size: 1
{
"name": "bbn-weixin-reply",
"dependencies": {
"browserify": "~> 10.2.4",
"browserify-incremental": "^3.0.1",
"coffee-reactify": "~> 5.0.0",
"urijs": "^1.18.1"
},
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
}
npm install
application.yml
/node_modules
### 各种猴子补丁
config.to_prepare do
# Load application's model / class decorators
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end
### browserify coffee 引用
config.browserify_rails.commandline_options = "-t coffee-reactify --extension='.coffee'"
libs.coffee
#= require jquery
#= require jquery_ujs
#= require turbolinks
#= require react
#= require react_ujs
#= require antd/antd-1.6.4.min
window.URI = require 'urijs'
application.coffee
# utils
window.ClassName = require 'utils/ClassName'
# http://fontawesome.io/icons/
window.FaIcon = require 'utils/FaIcon'
# # layouts
window.YieldComponent = require 'react/layouts/YieldComponent'
window.ConfigLayout = require 'react/layouts/ConfigLayout'
# components
window.WeixinConfig = require 'react/weixin/WeixinConfig'
!!!
%html
%head
%meta{:'http-equiv' => 'Content-Type', content: 'text/html; charset=UTF-8'}
%meta{:'http-equiv' => 'X-UA-Compatible', content: 'IE=edge, chrome=1'}
%meta{name: 'viewport', content: 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'}
%meta{name: 'renderer', content: 'webkit'}
%title Homepage
= stylesheet_link_tag 'application', media: 'all', :'data-turbolinks-track' => true
= javascript_include_tag 'libs', :'data-turbolinks-track' => true
= javascript_include_tag 'application', :'data-turbolinks-track' => true
= csrf_meta_tags
%body
:ruby
content_component = {
name: @component_name,
data: @component_data || {}
}
= react_component 'ConfigLayout', content_component: content_component
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def default_render
if @component_name.present?
@component_name = @component_name.camelize
return render template: '/index/component'
else
super
end
end
end
### 以下是自己添加的
Rails.application.config.assets.precompile += %w( libs.js )
# 生成不依赖数据库的工程
rails new test-app -O
复制 application.rb 代码
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
覆盖 config/environments 下三个文件,覆盖 config/initializers/new_framework_defaults.rb
在 config/environments/development.rb 中添加
# Mount Action Cable outside main process or domain
config.action_cable.allowed_request_origins = [ /http:\/\/*/ ]
以去除访问的 IP 限制
# app/config/initializers/warden_hooks.rb
Warden::Manager.after_set_user do |user, auth, opts|
scope = opts[:scope]
auth.cookies.signed["#{scope}.id"] = user.id.to_s
end
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.login
end
protected
def find_verified_user
if verified_user = User.find_by(id: cookies.signed['user.id'])
verified_user
else
reject_unauthorized_connection
end
end
end
end
参考:http://www.rubytutorial.io/actioncable-devise-authentication/
ant-design 的 js 和 css 是自己从他的源码编译的,编译之前修改了字号
修改 components/style/themes/default.less
中的
@font-size-base : 14px;
如果有其他想改的也可以在这里改
npm install
npm run dist
https://www.relishapp.com/rspec/rspec-expectations/v/3-2/docs/built-in-matchers
http://wulfric.me/2016/09/active-job-action-cable-in-rails/
http://www.thegreatcodeadventure.com/deploying-action-cable-to-heroku/
http://www.cnblogs.com/lxshanye/p/3560188.html https://developer.mozilla.org/en-US/docs/Web/API/notification