• 新增 “打赏” 功能 at February 24, 2017

    😄 😄

  • 新增 “打赏” 功能 at February 24, 2017

    不信的话,扫二维码试试 😌

  • 整理好你的问题,标题不要那么长

  • Change ActionView ERB Handler from Erubis to Erubi

    Erubi offers the following advantages for Rails:
    
    * Works with ruby's --enable-frozen-string-literal option
    * Has 88% smaller memory footprint
    * Does no freedom patching (Erubis adds a method to Kernel)
    * Has simpler internals (1 file, <150 lines of code)
    * Has an open development model (Erubis doesn't have a
      public source control repository or bug tracker)
    * Is not dead (Erubis hasn't been updated since 2011)
    
    Erubi is a simplified fork of Erubis that contains just the
    parts that are generally needed (which includes the parts
    that Rails uses).  The only intentional difference in
    behavior is that it does not include support for <%=== tags
    for debug output.  That could be added to the ActionView ERB
    handler if it is desired.
    
    The Erubis template handler remains in a deprecated state
    so that code that accesses it directly does not break.  It
    can be removed after Rails 5.1.
    

    https://github.com/rails/rails/commit/7da8d76206271bdf200ea201f7e5a49afb9bc9e7

  • DEPRECATION WARNING: The behavior of `attribute_change` inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_change_to_attribute` instead. (called from block (3 levels) in <top (required)> at spec/models/user_spec.rb:30)
    

    大量的这种 Warnning,看了一下,要清理需要非一些功夫了... attribute_changed? 这种用法很多地方都在用。

  • 如何将 Rails 5.0 升级 5.1

    修改 Gemfile

    gem 'rails', '~> 5.1.0.beta' 
    

    and run bundle update rails

    执行 rails app:update 检查 Rails 标准的几个文件的改动

    Overwrite config/secrets.yml? (enter "h" for help) [Ynaqdh] 
    

    遇到这类提示的时候,选 d,查看 Diff,根据情况手工修改你的文件。

    看起来重要的是 config/environments/production.rb 里面新增了一个配置:

    # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
    # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
    # `config/secrets.yml.key`.
    config.read_encrypted_secrets = true
    
  • #科技八卦

  • 实际上招聘需求目前来看,Ruby China 这样大段内容的作法能解决了。

    那么做会增加额外的复杂度,对于后期维护带来不便,权衡利弊,我觉得不应该那么做。

  • IT 人的辛苦,何来价值 at February 23, 2017

    居然还有功夫发帖,加班的事情也不是太急嘛

  • IT 人的辛苦,何来价值 at February 23, 2017

    😄 😄 😄 😄

  • 开发的时候,多关注你的 Rails 控制台日志才是应该的

  • 贴图看看 Emacs 写 Ruby 是什么样子。或者说说你的感受啥的

  • Bash 的环境和你登陆 SSH 到服务器的环境(环境变量)不同。

    所以你最好要在 rebuild_index.sh 里面载入 ~/.bashrc 之类的东西

    执行 rake 命令,最好是用 bundle exec rake 来执行,以确保 Gem 环境也能正确加载。


    主要错误是这个:

    cannot load such file -- bundler/setup
    

    看起来应该是 RubyGems 路径没对应上,执行的 rake 认为 bundler 没有安装。

  • 定义一个普通 scope 用的时候基于那个 scope,例如 Post.publish

  • 其实最好不要用 default_scope

  • 👏

  • 过来解释一下 at February 22, 2017

    #7 楼 @miclle 不是监控的问题,提示了也没看,因为那一瞬间我搞别的事情去了。 😅

  • 部署起来看看呀

  • 过来解释一下 at February 21, 2017

    然后原因是我执行了发布脚本干别的去了,忘了看

  • #8 楼 @lifuzho 不冲突,可以同时用的,我才尝试过。

  • Data Service 设计分享 at February 20, 2017

    #7 楼 @zhongfox second_level_cache 是 Write Through 的,在数据 update 的时候重写 cache 的。

    https://github.com/hooopo/second_level_cache/blob/master/lib/second_level_cache/mixin.rb#L76

  • Data Service 设计分享 at February 20, 2017

    #2 楼 @zhongfox 我知道 Node.js 并发查询的意义。

    我的意思是:

    let data = yield {
      '商品':  dataService.fetch(...),
      '广告':  dataService.fetch(...),
      '友情链接': dataService.fetch(...),
    }
    

    这段代码 dataService.fetch 实际上后面是从 Redis,还是一个 Rails API + Nginx Proxy Cache(或 Haproxy 之类的 HTTP 缓存实现),效果看起来似乎是一样的。

    因为看起来整个核心效率提高的原因碍于 Redis 里面存储的数据缓存(实际上看起来像是 Model 的二级缓存)。


    看你们的场景也用法,我设想假如引入 @hoooposecond_level_cache,或许你那层 DataService 到 Redis 的复杂实现都不需要了,Node.js 稍微实现一下这样的流程:

    Direct fetch from Cache 
            |
        [Cache] -> <hit> -> Response
            |
          <miss>
            |
        [fetch API] -> Write cache
            |
          Response
    
  • Ruby 的标准库是没有包含图像相关的实现的,有关于图形、图像相关的工作,大多都依赖 ImageMagick 来实现。

  • Data Service 设计分享 at February 20, 2017

    看起来你们的 DataService 不就是像 Thrift 那样的东西么?只不过没有单独服务跑,而是通过读写的时候放入 Redis。

    Update: 哦,不一样...

    我的问题是:

    1. 你怎么保障 write 动作的时候能正确的更新(或者设置失效)DataService Redis 的老数据,因为有时候查询关系是复杂的。
    2. 感觉你加了一层 Node.js 似乎和“扛百万压力”(顺便可以说一下是多少机器做到这个量),没直接关系,最后查询都要到 Rails 哪里,唯一区别是你的架构多了一层 Redis 的查询缓存。
    3. 看到有 expire_time 的参数,是每个查询都是固定的缓存一定的有效期么?如果是,那看起来像是 Proxy Cache 可以做的事情呀?你 after_save 那个动作如果只是单纯增对 id 有关的数据过期,Proxy Cache 的方式也是可以搞的。

    顺便提醒一个细节,要注意 after_save 并不是数据真的变了,有可能因为其他动作 Rollback 了,应该用 after_commit 来处理缓存过期。

  • rails.vim 以前一直不敢用,因为老的 Vim 没有 async 的实现,所有动作都是同步的,每个命令都要卡那么一下。

    rails.vim 提供了一些直接在 Vim 执行的 Rails 命令。但是在 Vim 8 之前 执行外部命令都是同步运行的,需要等待的时间比较久,这段时间不能在 Vim 不能做其他的操作。虽然 Vim 8 提供了异步模式,但大多数插件都没跟上。

    那么到底 rails.vim 改进了没有?还卡不卡?

  • #4 楼 @lifuzho 不知道能不能用,精力有限,要保持向下兼容需要费神一些。 😪 😶

    先把 gemspec 调整一下,你用用看,版本 0.1.3