<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>tumayun (tumayun)</title>
    <link>https://ruby-china.org/tumayun</link>
    <description>奋斗的coder</description>
    <language>en-us</language>
    <item>
      <title>!! 注意 delete_all 的坑</title>
      <description>&lt;p&gt;ActiveRecord 中有两个&lt;code&gt;delete_all&lt;/code&gt;方法：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/rails/rails/blob/c6f12715f1887c06f778a32330f59822ca77df20/activerecord/lib/active_record/relation.rb#L492" rel="nofollow" target="_blank" title=""&gt;ActiveRecord::Relation#delete_all&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rails/rails/blob/870d931b41abf5d20d25b1d444a35976d71bc110/activerecord/lib/active_record/associations/collection_proxy.rb#L499" rel="nofollow" target="_blank" title=""&gt;ActiveRecord::Associations::CollectionProxy#delete_all&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;很多人都知道第一个 &lt;code&gt;delete_all&lt;/code&gt;，后一个却没注意，我就是这种，今天踩了这个坑，给大家分享一下，避免有人继续踩坑！&lt;/p&gt;
&lt;h4 id="两个方法的区别"&gt;两个方法的区别&lt;/h4&gt;
&lt;p&gt;文档上已经写的很清楚了&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/rails/rails/blob/c6f12715f1887c06f778a32330f59822ca77df20/activerecord/lib/active_record/relation.rb#L492" rel="nofollow" target="_blank" title=""&gt;ActiveRecord::Relation#delete_all&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;不会走 callback 流程，不会查找对象，直接拼 SQL &lt;strong&gt;删除&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/rails/rails/blob/870d931b41abf5d20d25b1d444a35976d71bc110/activerecord/lib/active_record/associations/collection_proxy.rb#L499" rel="nofollow" target="_blank" title=""&gt;ActiveRecord::Associations::CollectionProxy#delete_all&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;我想当然的以为与上面的&lt;code&gt;delete_all&lt;/code&gt;方法行为一致，确实是差不多，不会走 callback 流程，不会查找对象，直接拼 SQL。但是要注意，这里并不一定是&lt;strong&gt;删除&lt;/strong&gt;，因为这里多了个&lt;code&gt;dependent&lt;/code&gt;参数，实际上这里的&lt;code&gt;delete_all&lt;/code&gt;会调用&lt;code&gt;delete_or_nullify_all_records&lt;/code&gt;，根据&lt;code&gt;dependent&lt;/code&gt;来确定是执行&lt;strong&gt;删除&lt;/strong&gt;还是执行&lt;strong&gt;nullify&lt;/strong&gt;。&lt;/p&gt;

&lt;p&gt;比如我在&lt;code&gt;Topic&lt;/code&gt; model 上这么写：&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:views&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;class_name: :TopicView&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;然后我执行：&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="vi"&gt;@topic.views.delete_all&lt;/span&gt; &lt;span class="c1"&gt;# 删除所有 views&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;实际上会执行与预期不符的 SQL:&lt;/p&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="nv"&gt;`topic_views`&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="nv"&gt;`topic_views`&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;`topic_id`&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="nv"&gt;`topic_views`&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;`topic_id`&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5927&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这时我应该加上&lt;code&gt;dependent&lt;/code&gt;参数，这样才能符合删除所有&lt;code&gt;views&lt;/code&gt;的预期&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="vi"&gt;@topic.views.delete_all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:delete_all&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 删除所有 views&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>tumayun</author>
      <pubDate>Fri, 07 Jul 2017 14:15:06 +0800</pubDate>
      <link>https://ruby-china.org/topics/33421</link>
      <guid>https://ruby-china.org/topics/33421</guid>
    </item>
    <item>
      <title>RSpec 如何更好的测试 call method</title>
      <description>&lt;p&gt;在写测试的时候经常要会出现如下情况&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:block_user!&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;other_user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;一般情况下这样挺好的，但是当涉及到查询时就非常麻烦了，比如在 controller 测试中&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="ss"&gt;:user&lt;/span&gt;
&lt;span class="n"&gt;other_user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;create&lt;/span&gt; &lt;span class="ss"&gt;:user&lt;/span&gt;
&lt;span class="n"&gt;sign_in&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt;
&lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:block_user!&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;other_user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="ss"&gt;:create&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;format: :json&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;user_id: &lt;/span&gt;&lt;span class="n"&gt;other_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;
&lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;have_http_status&lt;/span&gt; &lt;span class="ss"&gt;:success&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这样写测试肯定通过不了，虽然在 action 查询出来的 user 与 other_user 其实就是测试代码中的 user 和 other_user，但是查询出来的 object_id 与测试代码中的不同，所以会导致下面这句测试不通过！&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:block_user!&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;other_user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So，请教有没有什么 Gem 之类的对 receive 测试进行改进，使其就算 object_id 不同，也可以测试通过？
难道这种情况只能用如下方法解决？&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:find&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;and_return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to&lt;/span&gt; &lt;span class="n"&gt;receive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:find&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;other_user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;and_return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;other_user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;

&lt;p&gt;这里不讨论测试写的好不好，只说针对上述情况的 receive 测试有没有更好的解法！&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Tue, 15 Mar 2016 11:22:24 +0800</pubDate>
      <link>https://ruby-china.org/topics/29342</link>
      <guid>https://ruby-china.org/topics/29342</guid>
    </item>
    <item>
      <title>谨慎升级 omniauth-oauth2 到 1.4.0，你之前接入的 oauth 服务可能会出问题！</title>
      <description>&lt;p&gt;今晚老板 slack 我说 oauth 出问题了，但是我记得我没有做这方面的改动，这是见鬼了，只能在开发环境查一下啦。&lt;/p&gt;

&lt;p&gt;查的过程就省略不说，结果发现是在向第三方请求 token 的时候报错了。
完全没有道理啊，这东西怎么会出问题，然后自己把请求 &lt;code&gt;token&lt;/code&gt; 的参数粘贴下来试，鬼使神差的把 &lt;code&gt;callback_url&lt;/code&gt; 的 &lt;code&gt;query_string&lt;/code&gt; 删掉，居然请求成功了。
可是为什么会多了 &lt;code&gt;query_string&lt;/code&gt; 呢？想起一周前升级了一次 Gem，一看 &lt;code&gt;omniauth-oauth2&lt;/code&gt; 由 &lt;code&gt;1.3.1&lt;/code&gt; 升级到 &lt;code&gt;1.4.0&lt;/code&gt; 了，看了下 &lt;code&gt;omniauth-oauth2&lt;/code&gt; 的 commits，终于找到元凶（&lt;a href="https://github.com/intridea/omniauth-oauth2/commit/26152673224aca5c3e918bcc83075dbb0659717f" rel="nofollow" target="_blank" title=""&gt;Merge pull request #70 from intridea/dont-override-callback-url&lt;/a&gt;）了。&lt;/p&gt;

&lt;p&gt;很奇怪维护者们为什么要合并这个 PR，这明显会导致很多 oauth 服务出问题的，比如 &lt;code&gt;facebook&lt;/code&gt;，&lt;code&gt;dribbble&lt;/code&gt; 等等。
我目前的做法是将 &lt;code&gt;omniauth-oauth2&lt;/code&gt; 降级到 &lt;code&gt;1.3.1&lt;/code&gt;，似乎正确的做法是给 &lt;code&gt;omniauth-dribbble&lt;/code&gt; 提 PR，像 &lt;code&gt;omniauth-facebook&lt;/code&gt; 就更新了。&lt;/p&gt;

&lt;p&gt;最后祝各位永远不出 bug 😀&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Sun, 01 Nov 2015 23:39:59 +0800</pubDate>
      <link>https://ruby-china.org/topics/27918</link>
      <guid>https://ruby-china.org/topics/27918</guid>
    </item>
    <item>
      <title>Elasticsearch  如何用 script_fields 计算出来的字段进行排序？</title>
      <description>&lt;h3 id="示例如下："&gt;示例如下：&lt;/h3&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; GET &lt;span class="s1"&gt;'http://localhost:9200/users/user/_search?pretty'&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{
  "script_fields":{
    "distance":{
      "params":{
        "lat":23.1191,
        "lon":113.31
      },
      "script":"doc[\"location\"].distanceInKm(lat, lon)",
      "lang":"groovy"
    }
  }
}
'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="返回如下结果："&gt;返回如下结果：&lt;/h3&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# 2015-08-31T14:29:46+08:00 [200] (0.005s)&lt;/span&gt;
&lt;span class="c1"&gt;#&lt;/span&gt;
&lt;span class="c1"&gt;# {&lt;/span&gt;
&lt;span class="c1"&gt;#   "took":2,&lt;/span&gt;
&lt;span class="c1"&gt;#   "timed_out":false,&lt;/span&gt;
&lt;span class="c1"&gt;#   "_shards":{&lt;/span&gt;
&lt;span class="c1"&gt;#     "total":5,&lt;/span&gt;
&lt;span class="c1"&gt;#     "successful":5,&lt;/span&gt;
&lt;span class="c1"&gt;#     "failed":0&lt;/span&gt;
&lt;span class="c1"&gt;#   },&lt;/span&gt;
&lt;span class="c1"&gt;#   "hits":{&lt;/span&gt;
&lt;span class="c1"&gt;#     "total":11,&lt;/span&gt;
&lt;span class="c1"&gt;#     "max_score":1.0,&lt;/span&gt;
&lt;span class="c1"&gt;#     "hits":[&lt;/span&gt;
&lt;span class="c1"&gt;#       {&lt;/span&gt;
&lt;span class="c1"&gt;#         "_index":"users",&lt;/span&gt;
&lt;span class="c1"&gt;#         "_type":"user",&lt;/span&gt;
&lt;span class="c1"&gt;#         "_id":"4",&lt;/span&gt;
&lt;span class="c1"&gt;#         "_score":1.0,&lt;/span&gt;
&lt;span class="c1"&gt;#         "fields":{&lt;/span&gt;
&lt;span class="c1"&gt;#           "distance":[&lt;/span&gt;
&lt;span class="c1"&gt;#             12873.486133286819&lt;/span&gt;
&lt;span class="c1"&gt;#           ]&lt;/span&gt;
&lt;span class="c1"&gt;#&lt;/span&gt;
&lt;span class="c1"&gt;# }&lt;/span&gt;
&lt;span class="c1"&gt;#       },&lt;/span&gt;
&lt;span class="c1"&gt;#      ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;请问如何用 fields.distance 进行排序？&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;在 sort 中，不知道如何取到 distance 的值，所以也就无法写出 sort 子句，求解惑！！&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Mon, 31 Aug 2015 14:36:24 +0800</pubDate>
      <link>https://ruby-china.org/topics/27130</link>
      <guid>https://ruby-china.org/topics/27130</guid>
    </item>
    <item>
      <title>[已解决] 求教 SSL 证书是由未知名颁发机构签名问题</title>
      <description>&lt;p&gt;SSL 证书是由未知名颁发机构签名的，导致在诸如 RestClient 请求的时候要带上证书，不太想带上证书去请求，是不是有更好的方法？
将证书放在系统的特定目录就可以？&lt;/p&gt;
&lt;h3 id="解决方法"&gt;解决方法&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://kb.kerio.com/product/kerio-connect/server-configuration/ssl-certificates/adding-trusted-root-certificates-to-the-server-1605.html" rel="nofollow" target="_blank"&gt;http://kb.kerio.com/product/kerio-connect/server-configuration/ssl-certificates/adding-trusted-root-certificates-to-the-server-1605.html&lt;/a&gt;&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Thu, 27 Aug 2015 22:15:45 +0800</pubDate>
      <link>https://ruby-china.org/topics/27104</link>
      <guid>https://ruby-china.org/topics/27104</guid>
    </item>
    <item>
      <title>最近升级了 Rails 到 4.2.3，似乎发现了一个 Bug [已解决]</title>
      <description>&lt;p&gt;升级完后出现了个错误如下：&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;undefined&lt;/span&gt; &lt;span class="nb"&gt;method&lt;/span&gt; &lt;span class="sb"&gt;`length' for nil:NilClass

app/views/api/messages/unread.json.jbuilder, line 1

 - actionview (4.2.3) lib/action_view/helpers/cache_helper.rb:189:in `&lt;/span&gt;&lt;span class="n"&gt;write_fragment_for&lt;/span&gt;&lt;span class="s1"&gt;'
 - actionview (4.2.3) lib/action_view/helpers/cache_helper.rb:179:in `fragment_for'&lt;/span&gt;
 &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;actionview&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;4.2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;action_view&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;helpers&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;cache_helper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rb&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;115&lt;/span&gt;&lt;span class="ss"&gt;:in&lt;/span&gt; &lt;span class="sb"&gt;`cache'
 - app/views/api/messages/unread.json.jbuilder:1:in `&lt;/span&gt;&lt;span class="n"&gt;_app_views_api_messages_unread_json_jbuilder___3570167334891618967_70131777006720&lt;/span&gt;&lt;span class="s1"&gt;'
 - actionview (4.2.3) lib/action_view/template.rb:145:in `block in render'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;经调查在 &lt;code&gt;view&lt;/code&gt; 中使用 &lt;code&gt;cache&lt;/code&gt; 的时候，不知为何  &lt;code&gt;output_buffer&lt;/code&gt;  为 &lt;code&gt;nil&lt;/code&gt; ，感觉不像是 Rails 的 Bug，可能是 Jbuilder 之类的原因，具体原因还未找到。
请大家也试试自己的应用，看是否有相同的问题。&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# actionview-4.2.3/lib/action_view/helpers/cache_helper.rb#186&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;write_fragment_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#:nodoc:&lt;/span&gt;
  &lt;span class="c1"&gt;# VIEW TODO: Make #capture usable outside of ERB&lt;/span&gt;
  &lt;span class="c1"&gt;# This dance is needed because Builder can't use capture&lt;/span&gt;
  &lt;span class="n"&gt;pos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;output_buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;length&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt;
  &lt;span class="n"&gt;output_safe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;output_buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;html_safe?&lt;/span&gt;
  &lt;span class="n"&gt;fragment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;output_buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pos&lt;/span&gt;&lt;span class="o"&gt;..-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;output_safe&lt;/span&gt;
    &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;output_buffer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;output_buffer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;output_buffer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_fragment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fragment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id="Update"&gt;Update&lt;/h2&gt;
&lt;p&gt;这个问题排查了半天，回到升级前的版本一样出问题，经仔细比对代码，原来是我把 &lt;code&gt;json.cache!&lt;/code&gt; 给误删成 &lt;code&gt;cache&lt;/code&gt; 了！
真是脑残了，大家引以为戒~~&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Fri, 10 Jul 2015 16:16:59 +0800</pubDate>
      <link>https://ruby-china.org/topics/26432</link>
      <guid>https://ruby-china.org/topics/26432</guid>
    </item>
    <item>
      <title>【求助】iTerm2 中新开 Tab 后没有执行 RVM 脚本，没有自动切换 ruby-version 和 ruby-gemset</title>
      <description>&lt;p&gt;RT，有人遇到过吗？求助啊&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Wed, 22 Oct 2014 23:19:26 +0800</pubDate>
      <link>https://ruby-china.org/topics/22202</link>
      <guid>https://ruby-china.org/topics/22202</guid>
    </item>
    <item>
      <title>有什么 gem 能获取到 svg path 的 bounding box 吗?</title>
      <description>&lt;p&gt;有什么 gem 能获取到 svg path 的 bounding box 吗？
就像 JS 里面的 getBBox.
有没有 Ruby 版的实现？&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Tue, 12 Aug 2014 18:18:52 +0800</pubDate>
      <link>https://ruby-china.org/topics/20986</link>
      <guid>https://ruby-china.org/topics/20986</guid>
    </item>
    <item>
      <title>LinkedIn 因加班不给钱挨罚 向员工支付近 600 万美元</title>
      <description>&lt;p&gt;&lt;a href="http://it.people.com.cn/n/2014/0805/c1009-25406671.html" rel="nofollow" target="_blank"&gt;http://it.people.com.cn/n/2014/0805/c1009-25406671.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;这在中国有效吗？&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Tue, 05 Aug 2014 17:08:22 +0800</pubDate>
      <link>https://ruby-china.org/topics/20850</link>
      <guid>https://ruby-china.org/topics/20850</guid>
    </item>
    <item>
      <title>EOL for 1.8.7 and 1.9.2</title>
      <description>&lt;p&gt;&lt;a href="https://www.ruby-lang.org/en/news/2014/07/01/eol-for-1-8-7-and-1-9-2/" rel="nofollow" target="_blank"&gt;https://www.ruby-lang.org/en/news/2014/07/01/eol-for-1-8-7-and-1-9-2/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;小伙伴们，Ruby 1.8.7 和 1.9.2 即将停止维护了，升级吧！&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Fri, 11 Jul 2014 23:40:57 +0800</pubDate>
      <link>https://ruby-china.org/topics/20449</link>
      <guid>https://ruby-china.org/topics/20449</guid>
    </item>
    <item>
      <title>再回顾一遍 Ruby Gotchas</title>
      <description>&lt;p&gt;&lt;a href="http://blog.elpassion.com/ruby-gotchas/" rel="nofollow" target="_blank" title=""&gt;Ruby Gotchas that will come back to haunt you&lt;/a&gt;&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Tue, 29 Apr 2014 22:13:52 +0800</pubDate>
      <link>https://ruby-china.org/topics/18924</link>
      <guid>https://ruby-china.org/topics/18924</guid>
    </item>
    <item>
      <title>haml slim 之流真的好吗?</title>
      <description>&lt;p&gt;折腾死了，大改一个 haml 模版，好痛苦啊，从未体会这么深过.
逻辑片段非常难区分，一个个找，累死了.
当然，也是因为模版里面有很多逻辑，要区分逻辑片段简直亮瞎眼！&lt;/p&gt;

&lt;p&gt;纯吐槽下，勿喷！&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Thu, 24 Apr 2014 23:57:23 +0800</pubDate>
      <link>https://ruby-china.org/topics/18840</link>
      <guid>https://ruby-china.org/topics/18840</guid>
    </item>
    <item>
      <title>史上最变态验证码</title>
      <description>&lt;p&gt;注册 &lt;a href="http://www.freewebsitetemplates.com/" rel="nofollow" target="_blank"&gt;http://www.freewebsitetemplates.com/&lt;/a&gt;
然后你就明白了！&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Fri, 14 Mar 2014 17:48:50 +0800</pubDate>
      <link>https://ruby-china.org/topics/17887</link>
      <guid>https://ruby-china.org/topics/17887</guid>
    </item>
    <item>
      <title>Grape 用 Rack::Reloader 的时候出问题, endpoints 重复了....</title>
      <description>&lt;p&gt;最近用 Grape + Goliath 写 API，在 development 下 reload 出问题了.
导致 action 里面怎么改都是启动时候的代码，debugger 了半天，才发现 load 一次文件，endpoints 就又加载了一次，没有去重。&lt;/p&gt;

&lt;p&gt;详见 &lt;a href="https://github.com/intridea/grape/issues/552" rel="nofollow" target="_blank"&gt;https://github.com/intridea/grape/issues/552&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;不知道大家有遇到过这个问题不。&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Tue, 14 Jan 2014 20:05:15 +0800</pubDate>
      <link>https://ruby-china.org/topics/16804</link>
      <guid>https://ruby-china.org/topics/16804</guid>
    </item>
    <item>
      <title>2014 新年快乐</title>
      <description>&lt;p&gt;2014 了，大家新年快乐。&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Wed, 01 Jan 2014 00:07:53 +0800</pubDate>
      <link>https://ruby-china.org/topics/16551</link>
      <guid>https://ruby-china.org/topics/16551</guid>
    </item>
    <item>
      <title>Ruby 2.1 is coming!</title>
      <description>&lt;p&gt;Ruby 2.1 is coming!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.ruby-lang.org/en/news/2013/09/23/ruby-2-1-0-preview1-is-released/" rel="nofollow" target="_blank"&gt;https://www.ruby-lang.org/en/news/2013/09/23/ruby-2-1-0-preview1-is-released/&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="Changes"&gt;Changes&lt;/h2&gt;
&lt;p&gt;The notable changes are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;VM (method cache)&lt;/li&gt;
&lt;li&gt;RGenGC(See ko1’s &lt;a href="http://rubykaigi.org/2013/talk/S73" rel="nofollow" target="_blank" title=""&gt;RubyKaigi presentation&lt;/a&gt; and &lt;a href="http://www.atdot.net/~ko1/activities/Euruko2013-ko1.pdf" rel="nofollow" target="_blank" title=""&gt;Euruko presentation&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;refinements&lt;/li&gt;
&lt;li&gt;syntax&lt;/li&gt;
&lt;li&gt;Decimal Literal&lt;/li&gt;
&lt;li&gt;Frozen String Literal&lt;/li&gt;
&lt;li&gt;def’s return value&lt;/li&gt;
&lt;li&gt;Bignum&lt;/li&gt;
&lt;li&gt;128bit&lt;/li&gt;
&lt;li&gt;GMP&lt;/li&gt;
&lt;li&gt;String#scrub&lt;/li&gt;
&lt;li&gt;Socket.getifaddrs&lt;/li&gt;
&lt;li&gt;new RubyGems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;更多的详细更新内容： &lt;a href="https://github.com/ruby/ruby/blob/trunk/NEWS" rel="nofollow" target="_blank"&gt;https://github.com/ruby/ruby/blob/trunk/NEWS&lt;/a&gt;&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Fri, 11 Oct 2013 09:26:25 +0800</pubDate>
      <link>https://ruby-china.org/topics/14663</link>
      <guid>https://ruby-china.org/topics/14663</guid>
    </item>
    <item>
      <title>New Relic 现在注册并且部署成功就送一件 T-Shirt</title>
      <description>&lt;h3 id="Sign up now and get a free Nerd Life shirt"&gt;Sign up now and get a free Nerd Life shirt&lt;/h3&gt;
&lt;p&gt;我已经领了一件了，不过貌似要从国外寄过来？不知道什么时候能到。&lt;/p&gt;

&lt;p&gt;大家赶紧的！ &lt;a href="https://newrelic.com/" rel="nofollow" target="_blank"&gt;https://newrelic.com/&lt;/a&gt;&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Wed, 09 Oct 2013 20:06:55 +0800</pubDate>
      <link>https://ruby-china.org/topics/14626</link>
      <guid>https://ruby-china.org/topics/14626</guid>
    </item>
    <item>
      <title>有没有一种哈希算法，使得几个不同值经过哈希算法得到同一个结果？</title>
      <description>&lt;p&gt;有没有一种哈希算法，使得几个不同值经过哈希算法得到同一个结果？&lt;/p&gt;

&lt;p&gt;比如：&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;手机号&lt;/li&gt;
&lt;li&gt;用户名&lt;/li&gt;
&lt;li&gt;邮箱地址&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;经过哈希算法后得到同一个哈希值。或者说这样是否可行？&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Tue, 27 Aug 2013 23:30:57 +0800</pubDate>
      <link>https://ruby-china.org/topics/13682</link>
      <guid>https://ruby-china.org/topics/13682</guid>
    </item>
    <item>
      <title>Padrino 支持 Ruby 2.0 吗</title>
      <description>&lt;p&gt;没有在 Padrino 的文档中看到支持 Ruby 2.0.&lt;/p&gt;

&lt;p&gt;正在用 Padrino 的大牛们，有这方面的资料吗？&lt;/p&gt;

&lt;p&gt;&lt;a href="/Saito" class="user-mention" title="@Saito"&gt;&lt;i&gt;@&lt;/i&gt;Saito&lt;/a&gt;&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Wed, 10 Jul 2013 12:25:56 +0800</pubDate>
      <link>https://ruby-china.org/topics/12392</link>
      <guid>https://ruby-china.org/topics/12392</guid>
    </item>
    <item>
      <title>Rails 2 怎么测试有 subdomain 的 routes?</title>
      <description>&lt;h3 id="Rails 2 怎么测试有subdomain的routes?"&gt;Rails 2 怎么测试有 subdomain 的 routes?&lt;/h3&gt;
&lt;p&gt;希望有写过类似测试的哥们提供帮助.
或者有没有一些&lt;code&gt;Gem&lt;/code&gt;能做到。&lt;/p&gt;</description>
      <author>tumayun</author>
      <pubDate>Tue, 04 Jun 2013 11:02:54 +0800</pubDate>
      <link>https://ruby-china.org/topics/11470</link>
      <guid>https://ruby-china.org/topics/11470</guid>
    </item>
  </channel>
</rss>
