Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
小虫
@IChou
VIP
NO. 3035 / 2012-07-27

金金金 金数据
成都
8 Topics / 479 Replies
44 Followers
18 Following
12 Favorites
GitHub Public Repos
  • aliyun-oss-support 355

    基于阿里云OSS的WordPress远程附件支持插件

  • hugo-theme-vec 35

    Vec is a minimal, clean and beautiful theme for Hugo.

  • facepp-ruby-sdk 5

    A Ruby interface to the FacePlusPlus API.

  • xiami_radio 5

    Help you listening to the Xiami radio via a geek way

  • wechat-pay 0

    A simple Wechat pay ruby gem in api V3

  • llmprice.cn 0

    LLM price comparison 大模型价格对比

  • autocorrect 0

    A linter and formatter to help you to improve copywriting, correct spaces, words, and punctuation...

  • yii.im 0

  • wxocr 0

    This project wraps the WeChat OCR functionality from the excellent wechat-ocr project into a simp...

  • chat-langchain 0

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • [分享] 纯 API 项目的路由书写方式 at September 07, 2018

    他们直接抛弃了 RESTful

    应该是业务目前还够简单,controller 还没成长为裹脚布

  • 部署程序如何能达到一定并发量? at September 06, 2018

    这不只是 Rails 的问题吧,现在的『全栈框架』部署起来差不多都这个样子,毕竟涉及的东西就有这么多

    其实也没有多复杂,只是楼主可能没有仔细去看 Rails 部署相关的文章,走了很多弯路

    社区缺一篇相关的 Wiki 倒是真的

  • 推荐开源的 Ruby 学习书籍 at September 05, 2018

    第一本的发布日期就是 Mar 16, 2010,这还是发布时间,编写时间可能更早

    Ruby 跨了大版本的书对新人来说除了添乱,几乎一点帮助都没有

  • 服务器如何强行指定一次请求头的 Content-Type 为 application/json at September 05, 2018

    @ad583255925 请告诉我 对方是不是 java

  • 推荐开源的 Ruby 学习书籍 at September 05, 2018

    9 年前写的书还发 这不是坑人么 @huacnlee

  • 求助:当 undef_method 遇上 method_missing,rails 如何处理属性方法? at September 04, 2018

    看了下源码,如果没有 undef_method :name 就如你说的,会在第一调用的时候生成各种方法追加到 User 的实例方法中去,这个时候你调用 user.name 是不会触发 method_missing 的

    现在来说你 undef_method :name 的情况,首先它会落入下面的 method_missing 方法中

    # lib/active_model/attribute_methods.rb:425
    
    def method_missing(method, *args, &block)
      if respond_to_without_attributes?(method, true) # =>  这里是 false
        super
      else
        match = matched_attribute_method(method.to_s)
        #<struct ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher::AttributeMethodMatch target="attribute", attr_name="name", method_name="name">
        match ? attribute_missing(match, *args, &block) : super
      end
    end
    
    def attribute_missing(match, *args, &block)
      __send__(match.target, match.attr_name, *args, &block)
      # match.target => "attribute", 这里调用了自身的 attribute 方法
    end
    
    # lib/active_record/attribute_methods/read.rb:76
    def _read_attribute(attr_name) # :nodoc:
      @attributes.fetch_value(attr_name.to_s) { |n| yield n if block_given? }
    end
    alias :attribute :_read_attribute
    private :attribute
    

    这下明白了吧

  • 求助:当 undef_method 遇上 method_missing,rails 如何处理属性方法? at September 04, 2018

    没去看源码 做了个小实验

    class User < ActiveRecord
    end
    
    User.instance_methods.include?(:name) #=> false
    user = User.new
    User.instance_methods.include?(:name) #=> true
    
    user[:name] = 'admin'
    
    User.class_eval %q{undef_method :name}
    User.instance_methods.include?(:name) #=> false
    user.methods.include?(:name) #=> false
    user.name #=> "admin"
    

    看上去 attributes 的 methods 是懒加载的,只有在调用相关内容的时候才添加到 Class 里面,而且就算你把它从类里面 undef 掉,当你在实例上调用它时,它依旧会通过 method_missing 的 fallback 表现出正常的行为,应该算一种安全机制吧

  • 服务器如何强行指定一次请求头的 Content-Type 为 application/json at September 04, 2018

    最粗暴的 在 nginx 代理转发的时候改

    另外给路由指定 format: :json 能应对你们的情况么

  • 部署程序如何能达到一定并发量? at September 04, 2018

    nginx 的 root 目录应该指向 public 而不是根目录

    原则上 app 目录下的资源是不允许直接被 nginx 访问的,不需要 assets pipeline 管理的静态文件应该直接放到 public 目录下面去

  • 求助:当 undef_method 遇上 method_missing,rails 如何处理属性方法? at September 04, 2018

    不 include UserAddon 看看 User.methods 里面有没有 name 和 name=

  • 部署程序如何能达到一定并发量? at September 04, 2018
    # How many worker processes to run.  Typically this is set to
    # to the number of available cores.
    #
    # The default is "0".
    #
    # workers 2
    

    puma 自己对 worker 这个参数的解释,你每 new 一个 Rails 项目都能看到这段话

  • 部署程序如何能达到一定并发量? at September 04, 2018

    @xiaox https://github.com/puma/puma/blob/master/examples/config.rb#L107

  • 部署程序如何能达到一定并发量? at September 04, 2018

    另外你的 puma 配置里面,你只有一个核,开 3 个 worker 也没什么用,线程锁定 6 个也没什么意义,平时访问量很低的话 1, 6 应该会更合理

    吐个槽:问题可以改成 Rails 应用如何正确的部署 production,并发量问题对它而言太笼统了

  • 部署程序如何能达到一定并发量? at September 04, 2018

    怎么会 压测显示 fonts.googleapi.com 明明很快的很稳定呀

    @early 已经给出正确答案了

    另外在补充一下,Rails 编译静态资源的时候,默认就生成了 gzip(.gz)格式的文件,所以对 assets 下的资源 Nginx 可以启用

    gzip_static     on;
    
  • 部署程序如何能达到一定并发量? at September 03, 2018

    application.js 的平均响应时间 4s 最高 9s, 你直接把 js 请求交给 Rails 处理了么?

    生产环境要 assets:precompile 预编译,然后用 nginx 托管静态文件

  • 部署程序如何能达到一定并发量? at September 03, 2018

    压测做了没,现在能到多少?

    没有场景谈优化都是散吹,按你目前的机器,不换语言的情况下,干掉 Rails 只用 Rack 应该还能提升一些,but 你愿意么

  • 求助:rails 中使用 kindeditor 富文本编辑器网络上传没问题,本地上传错误 at August 29, 2018

    试一试 tower 的 simditor

    https://simditor.tower.im

    视频上传有插件实现

  • Rails 中使用 Nokogiri 和 Watir 实现 Spider at August 24, 2018

    https://www.rubydoc.info/gems/watir/Watir%2FBrowser.start

    start 就是 new + goto 吧,你是不是少写了 headless,所以 chrome 启动失败了

    Watir::Browser.start url, :chrome, headless: true
    
  • Ruby 的命名空间提案,引用包时避免污染全局环境 at August 20, 2018

    @jjym 对了,我很好奇你和 @jjyr 是什么关系😄 😄

  • 关于 homeland 论坛框架的几个问题 at August 20, 2018

    第一个问题是因为 homeland 使用了 turbolinks,页面切换时浏览器是没有刷新的,你目前的写法『那段 js 代码』只会在浏览器刷新时加载,所以你需要在适当时候手动触发一下 js 的动作

    老问题了,论坛里能搜到很多教程的

  • Rails 视图层? at August 20, 2018

    虽然最近在写 vue,但还是喜欢 erb + turbolinks 一把梭

  • Ruby 的命名空间提案,引用包时避免污染全局环境 at August 20, 2018

    向下兼容并不总是能解决所有问题,出了这个特性你用不用,一个项目里有的人用有的人不用,大丈夫?

  • Ruby China 搜索之后可不可以加个按时间排序 at August 19, 2018

    很早就自建 es 了

  • Ruby 的命名空间提案,引用包时避免污染全局环境 at August 19, 2018

    并没有觉得有很大的必要

    1. 不算痛点
    2. 对代码习惯影响略大,甚至可能会引入兼容性问题
    3. Ruby 不是提倡开放的么?这个 feature 写成个 gem 也能实现,为啥要作为通则
  • [征集话题]“我想问 Matz ?” 话题征集 at August 14, 2018

    楼上的两位,这个问题可能已经被问及无数次了,也回答过无数次了

  • 假如我出一个 Elixir Phoenix 的实践,会有人购买吗? at July 30, 2018

    可以先试看么 哈哈哈~~~ 也许会考虑

    歪个楼:从头开始学一个东西时,我还是习惯先买一本纸质书

  • cron 进程在任务执行结束后不被操作系统回收 at July 28, 2018

    为什么是 rails runner?不用 rake 么

  • 为何 rails c 里面下面这个会返回 false at July 27, 2018
    User === User.first
    # => true
    
    User === User
    # => false
    

    Ruby 的 === 不是恒等,而是验证归属性的

  • Rails inverse_of 研究 at July 22, 2018

    避免 sql 查询只是 inverse_of 的作用之一,它更重要的意义是保证上下文中 post 实例是同一个对象,如果它在某处被修改了,不会与 post 的另一份实例形成竞争关系

  • [译] 再见微服务,从 100 多个问题儿童到一个超级明星 at July 21, 2018

    微服务 这个概念本身我倒是觉得没什么黑的,我比较在意的是把 微服务 和 敏捷 放在一起的场景

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