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
  • [求助] 用 form_with 在发送没有 model 关联的 ajax 请求时遇到问题 at January 10, 2020

    你的理解是对的,ajax 请求只要有对应的.js.erb 文件就行。

    我怀疑是你浏览器发起的请求不是 ajax 请求。rails_ujs 的 ajax 请求的 request.formats 应该 text/javascript, 而你的是 text/html

    你可以浏览器检查元素,查看网络那块,点击表单后请求的类型是不是 XHR。如果不是 XHR,那很可能是 rails_ujs 的问题。

  • 从 ConnectionPool 中获取的 connection 什么时候会放回 Pool? at January 02, 2020

    1.可以,但不是必须的。rails 有新开一个线程,定期回收已死线程的连接。 https://github.com/rails/rails/blob/2f76256127d35cfbfaadf162e4d8be2d0af4e453/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L300

    2.不会

    3.http 请求结束时,释放。

    具体 4.2 的代码是在 rack 中间件里 https://github.com/rails/rails/blob/73521d586981279a99d3ba038d62e2414125df7a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb#L655

    5.2 的代码是在 query_cache 的 complete 里 (类似 after_action 里) https://github.com/rails/rails/blob/2f76256127d35cfbfaadf162e4d8be2d0af4e453/activerecord/lib/active_record/query_cache.rb#L37

  • 发现一个不错的 Ruby 文档网站 at November 19, 2019

    虽然有点砸场子😅 ,但我更推荐用 https://devdocs.io/,文档种类更多,也能自己搭,首次打开后会缓存到本地,之后打开速度就特别快。

  • ruby 中怎么实现可变变量 at October 17, 2019

    用 eval, 例如

    eval("$#{$key}")
    
  • [深圳南山] 一家对技术有要求的公司 AfterShip 正在招聘 Node.js, React.js, Golang, SRE, 大数据工程师! at August 07, 2019

    挺有趣的,招聘页面检查元素,藏了个 base64 的密文

  • 求教一个 Devise 使用问题 at June 05, 2019

    https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated 我没试过,仅供参考

  • 如何单独使用 active_support 中的 autoload at May 10, 2019

    楼主对 autoload 的理解是对的

    autoload :Base 
    

    会在引用 Base 常量,按需执行

    require('main/base')
    

    但 require 查找文件是根据$LOAD_PATH来找的,参考 wiki https://ruby-china.org/topics/28453

    楼上 $:就是$LOAD_PATH简写

  • 关于一个 (一个男人多个老婆) 嵌套表单的问题 at April 23, 2019

    https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

    params 里参数名改为 wives_attributes

  • 还有多少同学在做 Ruby 相关工作? at March 17, 2019

    9

  • Working with Unix Processes 的问题 at November 30, 2018

    Both signal handlers are called 因为 trap 会返回上一个信号的 handler https://ruby-doc.org/core-2.2.0/Signal.html#method-c-trap

    trap returns the previous handler for the given signal

  • ajax delete 请求后页面不刷新 at October 24, 2018

    我的经验是 ajax 的重定向应该

    render js: 'window.location.href=xxxxx'
    
  • cable wss 的问题 at August 27, 2018

    https://ruby-china.github.io/rails-guides/action_cable_overview.html

  • 货币格式问题,integer 转成:小数,带千分位,有更优雅的吗? at July 18, 2018

    也可以在非 view 的地方使用

    ActionController::Base.helpers.number_to_currency 7777777
    
  • form_for 辅助方法的第一个参数是指一个对象,这个对象是之前创建好的,还是新建的一个对象指代新建的表单? at July 05, 2018

    你看看《Rails 入门》后续的 5.11 节

    如果传入和实例变量(@article)同名的符号(:article),也会自动产生相同效果

    所以

    form_for :article
    

    等同于

    form_for @article
    
  • 关于一个 model 的怪问题 at April 14, 2018

    ::Equipment::Accepting 已经解决了常量查找的问题。

    tables not exist 是说数据库中不存在名字叫 Accepting 的表,你应该看看数据库表的名字是什么,对应改变 model 的名字。或者在 model 中写

    self.table_name = "你的表名"
    
  • 如何让不同的 model 关联不同类型的数据库? at April 04, 2018

    migration 里也要 establish_connection, 参考https://stackoverflow.com/questions/20502806/rails-migrate-with-different-databases

  • 想了解 require ” xx “, 或者 load "xx"真正的查找路径。 at September 13, 2017

    不好意思,我解释错了,应该是跟执行 ruby 的进程的文件夹有关。参考如下的 require 例子

    https://rubyplus.com/articles/4661-The-require-and-load-path-in-Ruby

  • 想了解 require ” xx “, 或者 load "xx"真正的查找路径。 at September 13, 2017

    因为这两文件在同一文件夹下,所以可以 load 成功吧。

    当前文件夹下找不到,再去 load_path 下找吧。

  • Prev
  • 1
  • 2
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English