Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
屎丸
@lithium4010
Member
NO. 8744 / 2013-08-19

上海
38 Topics / 613 Replies
11 Followers
47 Following
35 Favorites
GitHub Public Repos
More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • [北京][持续招聘呀.....] (玎少说,只要你敢来,我们就敢留) 来自新一代数据分析产品 GrowingIO 对 Ruby 工程师的邀请 (20K - 40K) at March 31, 2016

    跪一下

  • [上海] 点单宝急寻 Ruby 技术合伙人 [15K-25K+年终奖 + 股份期权] at March 28, 2016

    支持一下

  • [北京] 召唤 Ruby 工程师,一起探索个性化教育 at March 28, 2016

    不错支持一下

  • Rails 用到过哪些元编程? at March 11, 2016

    我项目里装逼用了 y-combinator 😄

  • Rails 4 中的 through 与 scope 共存时的 includes 查询,这个坑如何跳 at February 24, 2016

    那个 block 似乎应该放到 patient 里面

    class Physician < ActiveRecord::Base
      has_many :appointments
      has_many :patients,  through: :appointments
     has_many :healed_patients,  through: :healed_appointments, class_name: 'Appointment'
    end
    
    class Appointment < ActiveRecord::Base
      belongs_to :physician
      belongs_to :patient
      belongs_to :healed_patient, class_name: 'Patient',  foreign_key: 'patient_id'
    end
    
    class Patient < ActiveRecord::Base
      HEALED = 1
    
      has_many :healed_appointments, -> { where(state: Patient::HEALED).order('appointments.created_at DESC')}, class_name: 'Appointment'
      has_many :appointments
      has_many :physicians, through: :appointments
    end
    

    看起来像是 ActiveRecord 的 bug

    Physician.where_has_healed_patient.include(:patients).last # 找到有治愈病人的最后一个医生
    

    其实语义好像是这个的样子 我理解 include 只是用来拿“一对多”的“多”的,你的写法没有体现“找到有治愈病人的医生”这个意思,直接读是“我要所有医生中的最后一个,带上他的治愈病人的信息”。

    不是很清楚 rails 这里具体怎么实现,只是从语义上看。

    或者你就是是要找第一个医生,并带上他的治愈病人信息?

  • [已解决] 请教:如何让 elasticsearch 查询出来的数据,已经有序? at February 19, 2016

    也许有帮助 https://github.com/elastic/elasticsearch-rails/issues/10#issuecomment-35114080

    或者 30 条手动排序一下?

  • [结束] 送几本《Docker 即学即用》 at February 19, 2016

    [email protected]

  • Rails Model 继承的疑问 at February 18, 2016

    帮你找了 belongs_to 的源码 https://github.com/rails/rails/blob/21a386bb0726cce4f4a5d64d55fbb55d8a2b9837/activerecord/lib/active_record/associations/builder/belongs_to.rb

  • 整合 ElasticSearch 到现有 Rails 项目 at February 05, 2016

    我在项目里 monkey patch 了一下,实现了根据 mapping 自动生成 as_indexed_json

    # 用法
    settings index: { number_of_shards: 5 } do
          mappings do
            indexes :title,                type: 'string', :boost => 100, analyzer: "ik"
            indexes :content,              type: 'string', :boost => 50,  analyzer: "ik_smart",      as: ->(_){ self.content_text }
            indexes :current_state,        type: 'string', index: :not_analyzed, analyzer: :keyword, as: ->(_){ self.current_state.to_s }
        end
    
    
    # monkey
    
    # 去掉请求中的 as 部分
    class Elasticsearch::Model::Indexing::Mappings
      def to_hash
        { @type.to_sym => @options.merge( properties: @mapping.as_json(except: :as) ) }
      end
    end
    
    # 自动生成 as_indexed_json
    module Elasticsearch::Model::Serializing::InstanceMethods
    
      def as_indexed_json(options={})
        build_indexed_json(
          target.class.mappings.instance_variable_get(:@mapping),
          target,
          {id: target.id.to_s}
        ).as_json(options.merge root: false)
      end
    
    private
    
      def build_indexed_json(mappings, model, json)
        return json unless model.respond_to? :[]
    
        if model.kind_of? Array
          build_array_json(mappings, model, json)
        else
          build_hash_json(mappings, model, json)
        end
    
        json
      end
    
      def build_array_json(mappings, model, json)
        return json unless model.respond_to?(:[]) && json.kind_of?(Array)
    
        model.each do |elem|
          elem_json = if elem.kind_of? Array then [] else {} end
          json << elem_json
          build_indexed_json(mappings, elem, elem_json)
        end
      end
    
      def build_hash_json(mappings, model, json)
        return json unless model.respond_to?(:[]) && json.kind_of?(Hash)
    
        mappings.each_pair do |field, option|
    
          # Custom transformer
          if option.has_key?(:as) && option[:as].kind_of?(Proc)
            json[field] = target.instance_exec(get_field(model, field), &option[:as])
    
          # A nested field
          elsif option.has_key?(:properties)
            json[field] = if get_field(model, field).kind_of? Array then [] else {} end
            build_indexed_json(option[:properties], get_field(model, field), json[field])
    
          # Normal case
          else
            json[field] = get_field(model, field)
          end
        end
      end
    
      def get_field(model, field_name)
        model.try(:[], field_name) || model.try(field_name)
      end
    end
    
  • [上海] Strikingly 团队继续招聘 Ruby 工程师 / 运维工程师 ---- Hack 2016 at January 29, 2016

    终于 5:2 了

  • Rails & rails-html-sanitizer 安全性更新 at January 27, 2016

    谢谢 :plus1:

  • 关于动态生成类的疑问 at January 24, 2016

    #4 楼 @pathbox 关键是为什么前一句可以调用成功

  • 大家刚参加工作时的待遇、福利都是怎么样的? at January 23, 2016

    #75 楼 @mrpasserby 和 ruby 无关吧。。。

  • 大家刚参加工作时的待遇、福利都是怎么样的? at January 22, 2016

    #79 楼 @cisolarix 哈哈

  • 关于动态生成类的疑问 at January 22, 2016

    #1 楼 @w7938940 方法名就是 class

  • 大家刚参加工作时的待遇、福利都是怎么样的? at January 21, 2016

    2014 年 8 月上海 21.5k,Ruby 的话 14 年 12 月上海 8k

  • 模块与类的使用规范 at December 16, 2015

    ruby 本来就有点反对规范的意思

  • 元编程 —— 装逼专用?(其实用 Rails,并不需要太高的 Ruby 技能) at December 14, 2015

    觉得 if else 太多一般都是逻辑没有理清楚,没有做好 OO

  • 感觉 Node.js 也是 MongoDB 的命,忽悠一帮小青年 at December 14, 2015

    nodejs eventmachine 不用等 IO 速度快适合 web 应用啊

  • 一点 map 的心得 at December 14, 2015

    #1 楼 @kikyous Just 4 fun. 有些情况下还是有用滴。

  • 一点 map 的心得 at December 14, 2015

    好像可以这样

    class Object
      def lazy_send(method_name, *args)
        ->(obj=self) { obj.send method_name, *args }
      end
    end
    
    names.map(&lazy_send(:[], -1)) # 所有名字的最后一个字
    
  • 如何用 Ruby 实现类似 Clojure 中的 reducer? at July 15, 2015

    #1 楼 @yanhao 书上是用 clojure 的 reducer 来实现的 my-map

    你这样写是会遍历两次数组吧?

  • [上海][问] 在 Strikingly 工作是一个怎样的体验? [答] 再也回不去的感觉! at June 22, 2015

    可以和 joyce 一起去看话剧

  • 想询问一下链接点击统计的设计? at June 19, 2015

    给链接加一个 click 事件处理,ajax 把相关数据 post 给服务器

  • [思客教学]码农也能做出逼格破表的设计?抱团学 Sketch at June 16, 2015

    就差一个 mac 了

  • 怎么手写 form 表单 at June 12, 2015

    看这里 http://stackoverflow.com/questions/941594/understand-rails-authenticity-token

  • Render 一个 List 900ms 是不是很慢? 一般多长时间是可以接受的呢? at June 12, 2015

    #8 楼 @kgen development 和 production 差距挺大的,原因是什么呢?

  • Render 一个 List 900ms 是不是很慢? 一般多长时间是可以接受的呢? at June 11, 2015

    #16 楼 @limkurn 了解了,在 strikingly 的时候学到说时间长的请求丢到 job 里面去,返回 job_id 再从前端去请求 对应的 job, 为了避免一个连接占很长的时间

  • 寻找可以部署的 rails 的空间! at June 11, 2015

    heroku + 七牛,七牛管存图片,我反正这么做的

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