同求
只想去看妹纸 
通过 elasticsearch-transport  和 自定义 faraday middleware
PS:专修各种,150 起~
JRuby
# config/initializers/time_with_zone.rb
if defined?(::ActiveSupport)
  # ActiveSupport::JSON::Encoding.use_standard_json_time_format = false
  class ActiveSupport::TimeWithZone
    def as_json(opts = {}) # 可配置数据格式
      opts.assert_valid_keys(:date_format)
      opts[:date_format] ||= :default # 默认时间格式
      if ActiveSupport::JSON::Encoding.use_standard_json_time_format
        xmlschema(ActiveSupport::JSON::Encoding.time_precision)
      else
        self.to_s opts[:date_format]
      end
    end
  end
end
有个地方不明白,复杂的 scope 写成一个 Query 对象,这个文件放在那里?怎么看起来像个 Service  
目前的做法是写成 concerns 再 include 到 model类里。
同组测试:
[1] pry(main)> # 当前用户的GROUP
[2] pry(main)> current_user_groups = ['ADMIN', 'USER']
=> ["ADMIN", "USER"]
[3] pry(main)> # 被指派用户的GROUP
[4] pry(main)> assigned_user_groups = ['USER', 'TEST', 'GUEST']
=> ["USER", "TEST", "GUEST"]
[5] pry(main)> diff_group(current_user_groups, assigned_user_groups)
=> false
异组测试:
[1] pry(main)> # 当前用户的GROUP
[2] pry(main)> current_user_groups = ['ADMIN', 'USER', 'TEST']
=> ["ADMIN", "USER", "TEST"]
[3] pry(main)> # 被指派用户的GROUP
[4] pry(main)> assigned_user_groups = ['TEST', 'GUEST']
=> ["TEST", "GUEST"]
[5] pry(main)> diff_group(current_user_groups, assigned_user_groups)
=> true
我在用 gem 'bower-rails', '~> 0.11.0'
# 当前用户的GROUP
current_user_groups = ['ADMIN', 'USER']
# 被指派用户的GROUP
assigned_user_groups = ['USER', 'TEST', 'ADMIN']
=> true
起码应该这样:
# 判断指派人与被指派人是否同组 def diff_group(a, b) diff = false # 设置默认为同组 a.each do |k| b.each do |e| puts "#{k} <=> #{e}" diff = (k != e && e!= "TEST") end end diff end如果是俺理解错了,那也该这样:
# 判断指派人与被指派人是否同组 def diff_group(a, b) a.each do |k| b.each do |e| if k != e && e!= "TEST" puts "#{k} <=> #{e}" return true end end end false # 设置默认为同组 end
[1] pry(main)> [1,2,3] & [2,3,4]
=> [2, 3]
有意思 
默认编译参数:
ruby -r rbconfig -e 'RbConfig::CONFIG.sort.each { |c| p c }'
・
["optflags", "-O3 -fno-fast-math"]
・
・
rbenv 可以这样:
OPTFLAGS='-O3 -fno-fast-math -mllvm -inline-threshold=5000' rbenv install 2.3.1
ruby -r rbconfig -e 'puts RbConfig::CONFIG["OPTFLAGS"]'
→ -O3 -fno-fast-math -mllvm -inline-threshold=5000
要讲求沟通技巧,小项目用什么 PHP 呀,杀鸡用牛刀  
statistical_charging_piles 是什么,方法?
这需要一种建立一种机制,客户端收到消息后回执,标注过的消息从队列中删除,客户端上线(subscribed)后触发(未标示)队列。 
# -*- encoding: utf-8 -*-
class NotificationsChannel < ApplicationCable::Channel
  def subscribed
    stop_all_streams
    stream_from channel_id
    count # 连接后可触发
  end
  def unsubscribed
    stop_all_streams
  end
  def speak(data)
    ActionCableWorker.perform_async(channel_id, data) # Sidekiq 任务
  end
  def count
    speak( message: "当前连接数: #{ActionCable.server.connections.count}" )
  end
  private
    def channel_id
      "notifications:#{self.user_id || 'public'}"
    end
end
Let's Encrypt Authority X3  
@charleszhang 试试呗。 
# in app/middleware/catch_json_parse_errors.rb
class CatchJsonParseErrors
  def initialize(app)
    @app = app
  end
  def call(env)
    begin
      @app.call(env)
    rescue ActionDispatch::Http::Parameters::ParseError => e
      if env['HTTP_ACCEPT'] =~ /application\/json/
        error_output = "There was a problem in the JSON you submitted: #{e.message}"
        return [
          400, { "Content-Type" => "application/json" },
          [ { status: 400, error: error_output }.to_json ]
        ]
      else
        raise error
      end
    end
  end
end
# in config/application.rb
module YourApp
  class Application < Rails::Application
    # ...
    config.middleware.insert_after ActionDispatch::ShowExceptions, 'CatchJsonParseErrors'
    # ...
  end
end
#2 楼 @charleszhang Rails5 移除了 ActionDispatch::ParamsParser
# insert middleware wherever you want in the stack, optionally pass initialization arguments
  config.middleware.insert_before ActionDispatch::ParamsParser, Rack::Robustness do |c|
    c.no_catch_all
    c.on(ArgumentError) { |ex| 400 }
    c.content_type 'application/json'
    c.body{ |ex| 
      { 
        error: ex.message
      }.to_json
    }
    c.ensure(true) { |ex| env['rack.errors'].write(ex.message) }
  end if Rails.env.production? # 生产环境
不优化你的 SQL 逻辑,简单可以这样
plan = Plan.where('((start_time >= :start_at and start_time <= :end_at) or (end_time >= :end_at and end_time <= :end_at) or (start_time <= ? and start_time >= ?) or (start_time >= ? and start_time <= ?) or (start_time <= ? and end_time >= ?))',start_at: start_at, end_at : end_at)
PS: 问号我就不帮你一一替换了,手机不方便输入。