Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
秦阳
@zhuoerri
Member
NO. 32917 / 2017-09-13

成都
7 Topics / 55 Replies
21 Followers
0 Following
5 Favorites
GitHub Public Repos
  • rails_code_analysis 2

    rails源码粗解

  • godot-steam-p2p-multip... 0

  • lark-ruby-sdk 0

    Ruby SDKs for Lark(飞书) API https://open.feishu.cn/

  • json 0

    JSON implementation for Ruby

  • zhuoerri.github.io 0

  • rubyhackchallenge 0

  • casino 0

    fork from https://github.com/rbCAS/CASino

  • sunspot 0

    Solr-powered search for Ruby objects

  • HeroWar 0

    英雄远征个人理解以及解析

  • data-confirm-modal 0

    fork from kalelfc/data-confirm-modal

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 求助,安装 ruby 一直提示,任何版本都是。。。 at September 09, 2024

    可以试试用 rbenv 来安装,安装老版本 ruby 时,它会自动安装 1.0.2u 版的 openssl。

    一开始我本地测试安装时报错 ./openssl_missing.h:71:6: error: conflicting types for 'HMAC_CTX_copy', 根据 https://github.com/rbenv/rbenv/issues/661 解决方法是加环境变量 CFLAGS。加上后我本地安装成功了,我的安装命令如下

    CFLAGS="-Wno-error=implicit-function-declaration" rbenv install 2.0.0-p648

  • 请教,Rails 支持操作 word、excel 这些文档吗? at June 19, 2024

    https://github.com/ruby-docx/docx

    https://github.com/weshatheleopard/rubyXL

  • 请问一下 ruby 现在可以显示调用私有方法了(self.private_method)? at February 25, 2024

    搜了一下,是 2.7 版时改的

  • Gem::SourceIndex 没有被正确初始化 at December 13, 2023

    可能是 ruby 版本太老,或者 gem 版本太新,可以gem env 看看本地的 rubygems 版本

    谷歌搜到的建议是降 gem 版本 gem update --system 1.8.24 https://github.com/rubygems/rubygems/issues/536

  • Rails 路由问题请教 at May 06, 2023

    可以试试 constraints 选项,例如

    resources :programs, only: [:index], constraints: lambda { |req| req.format == :html }  do
    end
    
  • 垃圾回收原理浅析 at April 26, 2022

    ASCII 图用的 https://asciiflow.com/#/

  • YJIT 打算用 Rust 重写 at February 19, 2022

    https://github.com/artichoke/artichoke

    已经有了

  • YJIT 打算用 Rust 重写 at February 19, 2022

    谢谢楼上提醒,我的表述确实有歧义,已修改。

    因为我本地用的 arch linux,rvm 安装 ruby 时总是从源码编译安装。可能用更大众的 ubuntu 时,rvm 能直接安装现成的二进制包

  • 求助, includes 是如何双向绑定并且持久化的? at June 17, 2021
    • 如果你是想弄懂 触发sql和has_many 数据存在内存里的关系,你需要先看懂 Association 类和 Reflection 类 https://github.com/rails/rails/blob/v5.2.3/activerecord/lib/active_record/associations/association.rb

    https://github.com/rails/rails/blob/v5.2.3/activerecord/lib/active_record/reflection.rb

    • 然后 includes 是如何批量获取 sql 数据,并写入 Association 里的,你需要看 Preloader 类 https://github.com/rails/rails/blob/v5.2.3/activerecord/lib/active_record/associations/preloader.rb

    https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/activerecord/lib/active_record/associations/preloader/association.rb#L44

    • 最后判断 has_many 数据是否已在内存中的方法,具体是loaded? https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/activerecord/lib/active_record/associations/collection_proxy.rb#L54
  • 聊一下 turbo stream at June 07, 2021

    可能是 rubygems 版本的问题,我看你日志里的路径是 ruby/gems/3.0.0。 我本地用 rvm 安装 ruby 3.0 后,gem -v 返回 3.2.3, 能正常 gem install redis -v 4.2.5。

    但如果我切换 rubygem 版本 rvm install rubygems 3.0.0 --force , 或者 gem update --system 3.0.0 也会报错提示wrong number of arguments (given 2, expected 1

  • 聊一下 turbo stream at June 07, 2021

    试试删掉 C:/Ruby30-x64/lib/ruby/gems/3.0.0/cache/redis-4.2.5.gem 缓存内的 gem,重新安装。

    另外,看你的文件路径好像是 windows。社区不推荐新手用 windows https://ruby-china.org/wiki/install_ruby_guide

  • 超过 1 千万条数据,如何快速从 mysql 导入到 elasticsearch 中? at March 03, 2021

    我是用 searchkick 这个 gem 操作 ES 的。可以 异步 地把任务放 sidekiq 里执行来 reindex

    https://github.com/ankane/searchkick#parallel-reindexing

  • ractor 跑一段简单代码,百分百崩溃 at February 08, 2021

    试试加上 Ractor.yield 看还报错吗?

    e = (1..100000).to_a
    arr = [e,e,e,e]
    arr.map { |sub_arr|
      Ractor.new(sub_arr) do |sub_arr|
        Ractor.yield sub_arr.map {
          md5(rand.to_s)
        }
      end
    }.map{|r| r.take}.reduce(:+)
    
  • 各位同僚都用什么工具写 Rails? at January 28, 2021

    vim,主要插件如下

    Plug 'ervandew/supertab'

    Plug 'tpope/vim-commentary'

    Plug 'jremmen/vim-ripgrep'

    Plug 'junegunn/fzf.vim'

    Plug 'vim-syntastic/syntastic'

    Plug 'Shougo/deoplete.nvim'

  • 请教关于 Ruby 方法的一些问题 at January 16, 2021

    1.用 keyword parameter https://thoughtbot.com/blog/ruby-2-keyword-arguments 如下

    def test(x: 2, y: 3)
      x + y
    end
    
    test(y: 5)
    

    2.分号跟是否在 lambda 表达式里无关,就是分割语句用的。这个 y 没用

    3.test[0] 看成两步处理

    // 变量a等于test函数默认调用的结果,即5
    a = test
    // 5的二进制是101,所以5[0] == 1, 5[1] == 0, 5[2] == 1
    a[0] == 1
    a[1] == 0
    a[2] == 1
    
  • Ruby 3.0.0 Released at December 25, 2020

    👏 👏 👏

  • Rails 6.1 正式发布了~! at December 11, 2020

    数据库水平拆分 https://edgeguides.rubyonrails.org/active_record_multiple_databases.html

  • Rails 如何设置全局的 URL 前缀 at September 03, 2020

    但是这个只是改变了生成的 url,并不会改变实际的 url,如果真的需要拿到资源还是需要访问把 app 去掉的 url。

    换个思路,正式站的静态文件都是 rake assets:precompile 过的,直接用软链接改变实际的 url 就行

    ln -s ../public app

  • 如何为当前 URL append 参数? at June 23, 2020

    我看 kaminari 分页里是 to_unsafe_h,然后 except! 掉一些参数名 https://github.com/kaminari/kaminari/blob/ab8b1118bd721edc520a7cd32e0a72dc6d0d3608/kaminari-core/lib/kaminari/helpers/tags.rb#L25

    @params = template.params
    # @params in Rails 5 no longer inherits from Hash
    @params = @params.to_unsafe_h if @params.respond_to?(:to_unsafe_h)
    @params = @params.with_indifferent_access
    @params.except!(*PARAM_KEY_EXCEPT_LIST)
    @params.merge! params
    
  • rails 框架装不上 at May 25, 2020

    可以试试 https://ruby-china.org/topics/39879

  • 如何能获取到 Rails 引擎的名字? at May 15, 2020

    一般引擎内的 controller 的命令空间都带有引擎名吧,形如YourEngine::ControllerName直接调用 controller_path就行吧?

  • Ruby 和 Python 中对中文的处理 at May 12, 2020

    我没用过 python,但我执行你的 python 代码

    import json, hashlib
    
    params = {"key": '爱你'}
    
    u = json.dumps(params).encode('utf-8')
    # b'{"key": "\\u7231\\u4f60"}'
    

    返回的结果里,是单引号 包着双引号。因此\u被转义成了\\u。于是顺着这个思路,我把部分中文 utf8都 gsub 成了\\uXXXX 的形式

    require 'json'
    require 'digest'
    
    params = { "key": '爱你' }
    
    u = JSON.dump(params).gsub(':', ': ').gsub(',', ', ').gsub(/[\u4e00-\u9fa5]/) do |s| "\\u#{s.unpack('U')[0].to_s(16)}" end
    res = Digest::SHA256.hexdigest(u)
    puts res
    #  981727d14419aedca58b2e719b4a9ff94cf20ef91e02c9cd22e7ee6f5744f630
    
  • Rails 6 fails to integrate slick-carousel at April 30, 2020

    https://rossta.net/blog/how-to-customize-webpack-for-rails-apps.html#providing-jquery-as-an-import-to-legacy-plugins-and-exposing-to-global-scope

    可以试试上面用到的 expose-loader

  • 怎样才能让 format.rss 生成的 rss 页面点击的时候不直接下载呢? at April 30, 2020

    如果你确定是 content-type 的问题,可以用 response.headers 来设置 headers

  • 如何设置 rails console 中 app.host 的默认值? at April 23, 2020

    403 的原因应该跟 app.host 和 spec/下的helper都无关,你自己仔细检查下代码

  • 如何设置 rails console 中 app.host 的默认值? at April 23, 2020

    https://github.com/rails/rails/blob/66cabeda2c46c582d19738e1318be8d59584cc5b/railties/lib/rails/console/app.rb#L13

    没法配置,代码里写死了

  • Proc 以内变量继承外部变量的问题 at March 27, 2020

    这是闭包的特性,https://ruby-china.org/topics/38385

  • 生成 Excel 的时候,单元格能设置下拉可选则吗? at March 24, 2020

    可以用 axlsx 这个 gem,我当年抄的下拉框代码 https://gist.github.com/bradland/4228336

    如果是用 rubyXL 这个 gem,下拉框代码是 https://github.com/weshatheleopard/rubyXL/issues/340

  • Rails 项目部署腾讯 Ubuntu 16.04,部署报错 We're sorry, but something went wrong. at March 06, 2020

    一楼是以为你用的服务器是 puma,但你应该是用的支持 passenger 的 nginx。nginx 的默认日志位置在/var/log/nginx

  • rails 5.0.7 如何获取数据库中可用的数据连接数和已使用的线程数,需要把这个两个参数实时监控起来 at February 29, 2020

    如果你是指的 active_record 的连接池 connection_pool 的话,在源码 https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L345 里。

    @connections存了当前进程从数据库获取到的总连接;

    @available存@connections中空闲的,可分配给线程的连接;

    @thread_cached_conns是个 hash,存了@connections中已分配给线程的连接。

    # rails c例子
    # 连接池最多可以有多少个连接
    ActiveRecord::Base.connection_pool.instance_eval { @size }
    
    # 连接池目前已经从数据库获得了多少个连接
    ActiveRecord::Base.connection_pool.instance_eval { @connections.size }
    
    # 当前线程占用一个连接
    User.first
    ActiveRecord::Base.connection_pool.instance_eval { @connections.size }
    
    # 新起一个线程,又占用一个连接
    Thread.new {User.first; sleep}
    ActiveRecord::Base.connection_pool.instance_eval { @connections.size }
    
    # 查看每个线程占用的连接
    ActiveRecord::Base.connection_pool.instance_eval { @thread_cached_conns.keys }
    
    # 释放当前线程的连接
    ActiveRecord::Base.connection_pool.release_connection
    ActiveRecord::Base.connection_pool.instance_eval { @connections.size }
    ActiveRecord::Base.connection_pool.instance_eval { @available.instance_eval{@queue.size} }
    

    如果你是指数据库当前本身有多少个连接的话,mysql 的话,我查到是如下的 sql

    ActiveRecord::Base.connection.exec_query("show status where `variable_name` = 'Threads_connected';")
    
  • 1
  • 2
  • Next
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English