Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
@kenshin54
高级会员
第 165 位会员 / 2011-11-22

上海
22 篇帖子 / 550 条回帖
38 关注者
0 正在关注
0 收藏
GitHub Public Repos
  • popline 1059

    Popline is an HTML5 Rich-Text-Editor Toolbar

  • crane 14

    A mini linux container.

  • aws-simple-mfa 4

    Use AWS CLI with MFA enabled, but no Assume Role required.

  • firebase-admin-go 0

    Firebase Admin Go SDK

  • lilliput 0

    Resize images and animated GIFs in Go

  • gh-ost 0

    GitHub's Online Schema Migrations for MySQL

  • gifsicle 0

    Gifsicle is a suite of programs for manipulating GIF images and animations.

  • vim-snippets 0

    vim-snipmate default snippets (Previously snipmate-snippets)

  • minigc 0

    minimum gc

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • nestedset 是啥东西? at 2013年02月17日

    https://github.com/collectiveidea/awesome_nested_set

  • nestedset 是啥东西? at 2013年02月17日

    #5 楼 @i5ting 我没用它做过分页,主要用来实现树形结构的递归查询

  • nestedset 是啥东西? at 2013年02月17日

    nestedset

    lft 和 rgt 可以确定后代和祖先的范围

    对于 2 来说 lft 是 2,rgt 是 11,那所有 lft 在 2-11 之间的都是 2 的后代 对于 8 来说 lft 是 8,rgt 是 9,那 lft <= 8 且 rgt >= 9 的 即 7,2,1 是它的祖先

    单纯的用 parent_id 一个字断做树形结构,查询不便,oracle 有 connect by...start with...用法可以查,其他的好像要不然在数据库中存储过程或函数来实现

  • [上海] 凯业必达招聘 Rails 开发工程师 (再招一名 7 月 8 号更新) at 2013年02月04日

    纯吐槽,专业点啊,至少留个联系方式

  • 请问 Validations 可以只验证一个 form 提交的内容,或者指定验证吗? at 2013年02月02日

    Validations 可以加条件的啊 http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html#method-i-validates_numericality_of

  • gitlab 188 个 gem 震撼 at 2013年02月01日

    205 个飘过

  • [挖鼻] 我的第一个开源项目 [/ 挖鼻] at 2013年02月01日

    跪了。。

  • [暂停,详见帖子内容] OSChina 蛇年新春巨献:JetBrains 开发工具全场 2 折! at 2013年01月31日

    有没有人通过 AppCode,好不好用?

  • 下周二 (2 月 5 日) 晚上 网上现场 coding 第二季 (入场中...) at 2013年01月29日

    支持

  • 这段代码怎么去重复? at 2013年01月25日

    有一个想法,不过好像又麻烦了

    class LazyProc
      def initialize(_proc, *args)
        @proc = _proc
        @args = args
      end
    
      def call
        @proc.call(*@args)
      end
    end
    
    def specs_loop
      db_specs.map do |label, options|
        yield(LazyProc.new(method(:build_db).to_proc, label , options))
      end
    end
    
    if concurrent?
     specs_loop { |lp| Thread.new { lp.call } }.map(&:value)
    else
     specs_loop { |lp| lp.call }
    end
    
  • 关于具体技术与业务,在使用 rails 过程中,你是如何操作的? at 2013年01月24日

    根据你在http://ruby-china.org/topics/8347里问题

    个人感觉你把实体的具体化了到 java 的 Entity 上,其实做 rails 开发,或者说其他开发都是以需求分析,设计为先的,在设计时你说的实体并不需要以某种特定技术作为背景,可以仅仅只是业务模型或者领域模型。然后用你熟悉的任何工具来描述,比如 UML。

    在你用 java 和 hibernate 时,是通注解和属性的定义来生成的数据库表,实际上 hibernate 也是双向的,也可以通过数据库表生成 Entity。

    在 ruby 和 rails 里,更常用的是通过 migration 来管理数据库表,rails 会根据数据库表的字段来给 model 加上属性,不需要在 model 去写属性,更加不用一大堆 getter,setter。

    所以你的转换是的是从把业务模型 (实体)具化成 java 的 Entity 转换到把业务模型 (实体)具化成 active_record 的 model(通过 migration)

  • 同学们,你们是如何实现ORM的? at 2013年01月24日

    #8 楼 @zacker330 为什么不尝试转变你的思维,如果你一直用 hibrnate/jpa 的思想来用 active_record,以后只会越来越困难。比如假设你以前用 struts2 或 spring mvc,你习惯用注解来配置路由,但是 rails 就是写 routes.rb,尝试去理解和转换你的思想

  • 有这样的代理中间件吗? at 2013年01月23日

    #5 楼 @cxh116 我怎么感觉 nginx 就能做到,配置反向代理,用 ip_hash 做负载均衡,本身 nginx 也能做 failover,但是你的检测代理失效的具体需求可能不一样,还不如自己实现一个,需求也不是很复杂

  • 有这样的代理中间件吗? at 2013年01月23日

    #3 楼 @cxh116 具体我没试过,你可以尝试一下

    mechanize 有 post_connect 这个 hook,你可以在这个 hook 里根据 response,header 来得到信息,判断是否出错,然后用 set_proxy 方式切换代理

    这个 hook 只要是个能响应 call 方法的对象即可,和 rack 对象的参数有所区别,具体去查一下文档

    你可以吧这个 hook 单独出来,这样可以共用了

  • 有这样的代理中间件吗? at 2013年01月23日

    这样的 gem 不知道,但是自己实现一个简化版也很容易。

    1. 根据时间取模切换代理
    2. 定义个失败次数,超过次数切换代理
  • 这样的 dsl 怎么写? at 2013年01月22日

    这样吗?

    class Build
      def add_service(service)
        p "add service #{service}"
      end
    end
    
    def build_after(server, &block)
      Build.new.instance_eval(&block) if block_given?
    end
    
    build_after :some_server do
      add_service :my_service
    end
    
  • Github hosts 低调传播 at 2013年01月22日

    goodie

  • Nil Podcast (暂用名) 第 1 期发布 :) at 2013年01月21日

    不错 支持

  • 如何在 Rails development 模式下开启多线程并行处理 at 2013年01月21日

    我是这样试的

    我在 rails3 里,development.rb 里写config.threadsafe! 然后bundle exec thin start --thread 得到 thin 的 pid,top -pid thin_pid 终端里 repeat 10 (curl localhost:3000) 看到#TH 从 2 变成了 22,应该是开启了 (Mac 下的 top)

    P.S. rails s不行

  • 基本上能给业界流行的开源源件提交 Patch,都会让人对你刮目相看。 at 2013年01月19日

    没错,有时候不够自信,不敢提交 patch,我要多努力。

  • 推薦一個小工具 PopClip! at 2013年01月19日

    刚买 好用

  • 想买 Railscasts Pro at 2013年01月18日

    54RMB 不贵啊

  • {已解决}这个 chop! 有什么作用? at 2013年01月18日

    STDIN.gets 在用户输入后最后会有换行符,把换行符去掉

  • {已解决}这个 chop! 有什么作用? at 2013年01月18日

    http://www.ruby-doc.org/core-1.9.3/String.html#method-i-chop

    Returns a new String with the last character removed. If the string ends with \r\n, both characters are removed. Applying chop to an empty string returns an empty string. String#chomp is often a safer alternative, as it leaves the string unchanged if it doesn’t end in a record separator.

  • 类别可以复写吗? at 2013年01月18日

    #6 楼 @Rei 还是有稍许不一样的,不一样在于你创建对象的时机

    class Fruit
      def kind=(k)
        @kind = k
      end
    end
    
    apple = Fruit.new
    apple.kind = 'apple'
    #p apple.kind => undefined method `kind' 
    p apple.inspect
    
    class Fruit
      def kind
        @kind
      end
    end
    
    orange = Fruit.new
    orange.kind = 'orange'
    p orange.kind
    p orange.inspect
    
    class Fruit
      def inspect
        "a fruit of the #{@kind} variety"
      end
    end
    
    banana = Fruit.new
    banana.kind = 'banana'
    p banana.kind
    p banana.inspect
    
  • 请教 RSpec 的 Stub at 2013年01月17日

    你找错源码了,你用的 stub 是创建 Mock 对象的,你看的源码是 method_stub。你关注的地方的相关源码如下:

    https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/example_methods.rb#L40-L42

    def stub(*args)
      declare_double('Stub', *args)
    end
    

    一路跟踪到这里 https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/test_double.rb#L22-L26

    # Creates a new test double with a `name` (that will be used in error
    # messages only)
    def initialize(name=nil, stubs_and_options={})
      __initialize_as_test_double(name, stubs_and_options)
    end
    

    以及这里 https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/test_double.rb#L55-L64

    def __initialize_as_test_double(name=nil, stubs_and_options={})
      if name.is_a?(Hash) && stubs_and_options.empty?
        stubs_and_options = name
        @name = nil
      else
        @name = name
      end
      @options = extract_options(stubs_and_options)
      assign_stubs(stubs_and_options)
    end
    

    具体只有 inspect 用到 https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/test_double.rb#L37-L39

    def inspect
      "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>"
    end
    

    说白了,就是给个名字,错误显示里看得清楚点

  • [杭州] 阿里巴巴继续招两个 Ruby 工程师 at 2013年01月17日

    阿里旺旺是属于 etao 的 0.0

  • 这个代表什么? at 2013年01月17日

    😳

  • iccfish/12306_ticket_helper,一个惊动了 GitHub 运营小组的项目 at 2013年01月15日

    考验 github 的时候到了

  • 异步请求服务器 url 还会变的技术是 pjax? at 2013年01月14日

    实际上是 pushState 和 replaceState https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history

    pjax 和 turbolinks 都是基于这个来实现的

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