Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
嗨小毛
@jmmbite
Member
NO. 13225 / 2014-05-21

国企
杭州
9 Topics / 83 Replies
0 Followers
0 Following
97 Favorites
做个快乐有趣的程序员
No GitHub.
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 如何返回一个成员变量的引用 at October 19, 2018

    还是基础过一遍吧。也就一天的事。

  • 如何在不使用全局变量情况下保持变量内容呢 at September 11, 2018
    *.previous_changes
    
  • Rails 网站被恶意攻击,请求如何防御 at September 10, 2018

    这应该是第三方查询 12306 的余票系统。

  • 关于 weixin_authorize 的问题 at September 03, 2018

    服务号可以向关注的所有用户发送消息。

  • 所有用 Rails 写的网站,在参数后面加上?foo=%9g,都会直接返回一个 400,而且好像抓不住这个报错 at August 29, 2018

    感觉 rack 有些参数不忽略,没处理好引起的问题。😂

    改成: 多重类别参数,根据前后顺序,只取前面就好了,后面的一律忽略。 production 环境忽略,其它环境报错。

    Puma caught this error: Invalid query parameters: expected Hash (got Array) for param `datas' (ActionController::BadRequest)
    /usr/local/ruby/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/query_parser.rb:112:in `normalize_params'
    /usr/local/ruby/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/query_parser.rb:67:in `block in parse_nested_query'
    /usr/local/ruby/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/query_parser.rb:64:in `each'
    /usr/local/ruby/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/query_parser.rb:64:in `parse_nested_query'
    

    或者可以参考,php 的处理方式:

    info.php?datas[]=1&datas[id]=2&datas[]=3
    
    _REQUEST["datas"]   
    Array
    (
        [0] => 1
        [id] => 2
        [1] => 3
    )
    
    _GET["datas"]   
    Array
    (
        [0] => 1
        [id] => 2
        [1] => 3
    )
    
  • 所有用 Rails 写的网站,在参数后面加上?foo=%9g,都会直接返回一个 400,而且好像抓不住这个报错 at August 29, 2018
    Puma caught this error: Invalid query parameters: invalid %-encoding (%9g) (ActionController::BadRequest)
    /usr/local/ruby/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/query_parser.rb:72:in `rescue in parse_nested_query'
    /usr/local/ruby/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/query_parser.rb:60:in `parse_nested_query'
    /usr/local/ruby/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/request.rb:468:in `parse_query'
    /usr/local/ruby/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/request.rb:319:in `GET'
    

    找到位置,调试就好了。程序要重启。

  • 所有用 Rails 写的网站,在参数后面加上?foo=%9g,都会直接返回一个 400,而且好像抓不住这个报错 at August 29, 2018

    提一个 pull request 就好了,应该是解析出问题的。

    unescape 改成 URI.unescape 就好了。

    https://github.com/rack/rack/pull/1292/files

    本地测试,正常了。

  • Rails 管理多数据库 at August 25, 2018

    multi domain

  • [求助] Rails 5.2 多重多态怎么获取正确的 url? at August 22, 2018

    /rails/info/routes 看一下 comment_reports_path 有没有这个,需要加@comment参数的

  • 请问如何写成下面这个 json 的 API? at August 07, 2018

    https://ruby-china.org/topics/25330#reply39

  • 把一个巨大的 hash 放在一个类的常量里面,和作为方法放在类里面,哪个比较好 at July 31, 2018

    ruby 万物皆对象,常量是最专一的。

  • 把一个巨大的 hash 放在一个类的常量里面,和作为方法放在类里面,哪个比较好 at July 31, 2018

    我是 独立一张配置表,启动一次性读完丢入 redis

  • belongs_to 中 accepts_nested_attributes_for 新增一条数据的问题? at July 29, 2018

    补上,class ApplicationRecord < ActiveRecord::Base 代码

    class ApplicationRecord < ActiveRecord::Base
      after_save :trace_log
      after_destroy :trace_log
      def trace_log
        if @_trigger_update_callback
          after_on = 'update'
        elsif @destroyed
          after_on = 'destroy'
        else
          after_on = 'create'
        end
        puts "#{self.class.name}:#{after_on}"
      end
    end
    
  • Postgresql 插入一亿条数据,有快速的方法吗? at July 25, 2018

    😂

  • Postgresql 插入一亿条数据,有快速的方法吗? at July 25, 2018

    因为试过了才得出的结论, 非 ssd,插入时间超过 30 分钟以上了,后面我就直接中断退出了。

    psql (9.6.9)
    Type "help" for help.
    
    postgres=# insert into topics select generate_series(2,100000000),2,1,1;
    

    参考的是这篇帖子:1 亿条数据中 PostgreSQL 性能/

    但是自己的测试结果并没有这么快,所以我想是不是从 postgresql 的 C 接口直接插入是否会更快,消耗更少。

    因为第一次使用 pg,不知道该引用那个头文件更合适,不过已经把各种都测过了

    最后还是参考了,官方文档,代码很简单就不贴了

    https://www.postgresql.org/docs/10/static/libpq-example.html

    https://www.postgresql.org/docs/10/static/xfunc-c.html

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

    搜索::currency

    https://github.com/rails/rails/search?q=%3Acurrency&unscoped_q=%3Acurrency

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

    👍 这种方法文档直接搜搜不到,看来只能从源码入手了😂 NumericWithFormat http://api.rubyonrails.org https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/numeric/conversions.rb

  • [已解决] V2EX 挂了? at July 21, 2018

    不是有个故事吗,砍柴的跟放羊的聊了一天,很开心!!

    放羊的一天过去了,羊吃饱了。

    砍柴的一天过去了,什么也没干嘛。

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

    rubymoney,也考虑用过,最后花了点时间,给 number_to_currency 加了一层来处理。

    本着能不用 gem 尽量不用的原则。各项配置能入库一律入库。

    currencies 和 number_to_currency 的各项参数,每一种货币的配置写入数据库。

    增加了一个 cents 参数:

    1 单位的货币 = 多少 cents,

    积分的话:1 unit = 1cents

    人民币:1 unit = 100 cents

    最后配合:precision 参数,基本没差别了

    def money(credit, currency)
      number_to_currency(
        credit*1.0/currency.cents, unit: currency.unit, 
        delimiter: currency.delimiter, separator: currency.separator, precision: currency.precision, 
        format: currency.format, 
      )
    end
    
    # or
    
    def money(credit, currency)
      number_to_currency( credit*1.0/currency.cents, currency.attributes )
    end
    

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

    这个好像只能在 views 使用,controllers 不能使用,需要在 notice 等提示中使用。

  • 想做一个关注主题的功能,请问有没有最佳实践? at July 15, 2018
    Topic.where(user_id: [current_user.id , 关注的用户ids])
    
    然后与主信息流合并ids
    
  • 在 after_commit 里如何判断当前操作是通过 [:create, :destroy, :update] 中的哪一个进来的? at July 12, 2018

    就是因为不想分 3 次😂

  • 今年的 RubyConf 大概啥时候呢? at June 26, 2018

    金三银四,刚好:十月怀胎。

  • 最近几天,网站一直无法打开 at December 27, 2016

    #4 楼 @huacnlee 已经可以正常访问了!😊

  • 大疆发布掌上无人机 Mavic Pro,重仅 743 克,飞行时间 27 分钟 at September 28, 2016

    续航是硬伤😀

  • Ruby China 基于 Turbolinks 的 iOS 以及 Android 客户端发布了 at September 24, 2016

    希望点图片后,能支持图片预览切换

  • 下线 Gravatar 头像功能,改由 letter_avatar 代替,并且没上传头像不允许发帖了 at October 28, 2015

    @huacnlee 有个小 bug,未登陆情况下右边侧栏有上传头像的功能,如下图:

  • 欢迎 3 位新的 Ruby China 社区管理员 at October 14, 2015

    :plus1:

  • 征集大家意见,关于回帖用树形方式展示,类似 HackerNews at August 10, 2015

    👎 有种回到过去的感觉。 可以设置成,鼠标移动到 #13 楼 @huacnlee 并浮动显示指向这条的评论。页内的评论可以调用,就是跨页需要改成 ajax 方式调用。

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