<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>rubyonme (Mr.shi)</title>
    <link>https://ruby-china.org/rubyonme</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>API 设计参数传递使用 id 是最佳方案？</title>
      <description>&lt;h3 id="需求描述"&gt;需求描述&lt;/h3&gt;&lt;h5 id="类似电影院的选座需求，在下单的时候传递预定的座位"&gt;类似电影院的选座需求，在下单的时候传递预定的座位&lt;/h5&gt;&lt;h3 id="问题"&gt;问题&lt;/h3&gt;&lt;h5 id="关于下单的 API 设计，在传递座位参数的时候是传递座位 seat 的 id 更好，还是传递如 A-1  这样的人容易理解的参数更好？"&gt;关于下单的 &lt;code&gt;API&lt;/code&gt; 设计，在传递座位参数的时候是传递座位 seat 的 &lt;code&gt;id&lt;/code&gt; 更好，还是传递如 &lt;code&gt;A-1&lt;/code&gt;  这样的人容易理解的参数更好？&lt;/h5&gt;&lt;h3 id="相关背景"&gt;相关背景&lt;/h3&gt;&lt;h4 id="目前团队内争议较大，争议的地方存在以下几个方面："&gt;目前团队内争议较大，争议的地方存在以下几个方面：&lt;/h4&gt;&lt;h5 id="1.  API 数据设计不需要考虑人的可读性，所以应该传 id"&gt;1.  API 数据设计不需要考虑人的可读性，所以应该传 &lt;code&gt;id&lt;/code&gt;
&lt;/h5&gt;&lt;h5 id="2 . 数据库查找的时候，使用 id 性能更好"&gt;2 . 数据库查找的时候，使用 &lt;code&gt;id&lt;/code&gt; 性能更好&lt;/h5&gt;&lt;h5 id="3.  使用座位号如 A-1，程序里还要去分割处理"&gt;3.  使用座位号如 &lt;code&gt;A-1&lt;/code&gt;，程序里还要去分割处理&lt;/h5&gt;&lt;h3 id="我的观点"&gt;我的观点&lt;/h3&gt;&lt;h5 id="1. 可读性是更重要的"&gt;1. 可读性是更重要的&lt;/h5&gt;&lt;h5 id="2. 性能不应该过早优化"&gt;2. 性能不应该过早优化&lt;/h5&gt;&lt;h5 id="3. 使用座位号，这样会把座位号当做一个整体处理，更契合业务逻辑"&gt;3. 使用座位号，这样会把座位号当做一个整体处理，更契合业务逻辑&lt;/h5&gt;
&lt;p&gt;想征求一下大家的意见，哪种设计会更好？&lt;/p&gt;</description>
      <author>rubyonme</author>
      <pubDate>Wed, 09 Sep 2015 12:37:32 +0800</pubDate>
      <link>https://ruby-china.org/topics/27251</link>
      <guid>https://ruby-china.org/topics/27251</guid>
    </item>
    <item>
      <title>bundle install 出现 uninitialized constant Gem::Security::Policies </title>
      <description>&lt;p&gt;bundle install 出现
gems/bundler-1.3.0/lib/bundler/cli.rb:174:in `&lt;a rel="nofollow" target="_blank"&gt;class:CLI&lt;/a&gt;': uninitialized constant Gem::Security::Policies (NameError)
什么情况？&lt;/p&gt;</description>
      <author>rubyonme</author>
      <pubDate>Sat, 22 Feb 2014 10:24:52 +0800</pubDate>
      <link>https://ruby-china.org/topics/17408</link>
      <guid>https://ruby-china.org/topics/17408</guid>
    </item>
    <item>
      <title>有没有办法拦截特定 sql 语句，返回修改后的结果？</title>
      <description>&lt;p&gt;比如原始 sql 为
select * from tests where a=1;
拦截此 sql 语句并返回 select * from tests where a=2 的查询结果。
数据库是 sqlserver，由于客户端实在没法修改，所以才想到此方式。&lt;/p&gt;</description>
      <author>rubyonme</author>
      <pubDate>Thu, 20 Feb 2014 09:36:47 +0800</pubDate>
      <link>https://ruby-china.org/topics/17362</link>
      <guid>https://ruby-china.org/topics/17362</guid>
    </item>
    <item>
      <title>集成支付宝付款求助</title>
      <description>&lt;p&gt;使用 ruby 1.9.3 rails 3.2.8
根据  &lt;code&gt;activemerchant_patch_for_china&lt;/code&gt;  的示例代码&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.total_fee &lt;/span&gt;&lt;span class="vi"&gt;@amount&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.seller &lt;/span&gt;&lt;span class="ss"&gt;:email&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="vi"&gt;@config.ali_seller_email&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.notify_url &lt;/span&gt;&lt;span class="n"&gt;url_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:only_path&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:action&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'pay_notify'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.return_url &lt;/span&gt;&lt;span class="n"&gt;url_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:only_path&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:action&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'pay_done'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.show_url &lt;/span&gt;&lt;span class="n"&gt;url_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:only_path&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:action&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'show_search'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.body &lt;/span&gt;&lt;span class="s1"&gt;'测试中文'&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.charset &lt;/span&gt;&lt;span class="s2"&gt;"utf-8"&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.service &lt;/span&gt;&lt;span class="no"&gt;ActiveMerchant&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Billing&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Integrations&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Alipay&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Helper&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;CREATE_DIRECT_PAY_BY_USER&lt;/span&gt; &lt;span class="sx"&gt;%&amp;gt;
  &amp;lt;% service.payment_type 1 %&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.paymethod &lt;/span&gt;&lt;span class="s1"&gt;'bankPay'&lt;/span&gt;&lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.subject &lt;/span&gt;&lt;span class="s1"&gt;'test'&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% service.sign &lt;/span&gt;&lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;lt;% service.body '测试中文' %&amp;gt; 这句如果换成英文是没有问题的，如果是中文支付宝会返回 &lt;code&gt;错误代码 ILLEGAL_SIGN&lt;/code&gt;。
大概的研究了一下是因为&lt;code&gt;&amp;lt;% service.sign %&amp;gt;&lt;/code&gt;这个签名的生成的不对。
看了下 &lt;code&gt;activemerchant_patch_for_china&lt;/code&gt;  的源代码，问题出在这句&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;add_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'sign'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                      &lt;span class="no"&gt;Digest&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;MD5&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="vi"&gt;@fields.sort.collect&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s2"&gt;"="&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="no"&gt;CGI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unescape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])}).&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;amp;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="no"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                     &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;有人知道是怎么回事吗？&lt;/p&gt;</description>
      <author>rubyonme</author>
      <pubDate>Wed, 29 Aug 2012 15:07:44 +0800</pubDate>
      <link>https://ruby-china.org/topics/5228</link>
      <guid>https://ruby-china.org/topics/5228</guid>
    </item>
    <item>
      <title>mongoid 3 应该怎样切换数据库连接？</title>
      <description>&lt;p&gt;mongoid 3 的数据库连接配置都在 &lt;code&gt;mongoid.yml&lt;/code&gt; 的 &lt;code&gt;sessions&lt;/code&gt; 下，找了半天也没有找到怎样整体切换 &lt;code&gt;session&lt;/code&gt; 的方式。  &lt;/p&gt;</description>
      <author>rubyonme</author>
      <pubDate>Sat, 02 Jun 2012 15:19:31 +0800</pubDate>
      <link>https://ruby-china.org/topics/3619</link>
      <guid>https://ruby-china.org/topics/3619</guid>
    </item>
    <item>
      <title>有熟悉 Fiber 的吗，Fiber 应该怎样销毁？</title>
      <description>&lt;p&gt;目前做的项目是采用 Fiber 来处理多个异步请求，比如一个 method 需要 3 步完成：
1: 查询 redis
2: socket 发送信息
3: 处理 socket 返回信息&lt;/p&gt;

&lt;p&gt;每一个执行步骤中间都需要调用 &lt;strong&gt;Fiber.yield&lt;/strong&gt; 使得相应的 fiber 休眠。正常情况执行完 3 个步骤 fiber 就退出了，但如果某个步骤没有正常返回，fiber 就不会执行完毕，就会产生未执行完毕的 fiber，占用系统内存。&lt;/p&gt;

&lt;p&gt;Fiber 没有 exit 之类的方法，那么这些未执行完毕的 fiber 应该怎样退出或者销毁呢？  &lt;/p&gt;</description>
      <author>rubyonme</author>
      <pubDate>Mon, 14 May 2012 12:06:16 +0800</pubDate>
      <link>https://ruby-china.org/topics/3257</link>
      <guid>https://ruby-china.org/topics/3257</guid>
    </item>
    <item>
      <title>什么情况，MongoDB 被清空？</title>
      <description>&lt;p&gt;机房服务器电源不小心被碰掉，启动后 mongodb 数据库变成空的了，一条数据也查询不到了，这是什么情况，有人遇到过吗？  &lt;/p&gt;</description>
      <author>rubyonme</author>
      <pubDate>Wed, 02 May 2012 17:16:13 +0800</pubDate>
      <link>https://ruby-china.org/topics/3031</link>
      <guid>https://ruby-china.org/topics/3031</guid>
    </item>
    <item>
      <title>关于 node.js pub/sub 的问题</title>
      <description>&lt;p&gt;目前要做一个&amp;nbsp;&amp;nbsp;rails+mongodb+node.js 的项目，关于 node.js，有点疑问：
node.js 对于 io 的访问是非阻塞的，但如果需要访问 2 个资源，如果采用嵌套，比如：&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="c1"&gt;//some func&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这样只有当 a 成功返回后，b 执行 get 方法，这样的嵌套相当与阻塞了 b 的执行。
a,b 应该是同时执行，这样就需要 pub／sub 功能，&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="c1"&gt;//发出事件，a执行完毕&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
 &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="c1"&gt;//发出事件，b执行完毕&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;目前采用的解决办法是采用 redis 的 pub／sub 功能，但是总感觉不应该依赖 redis，node.js 本身有什么好的 pub/sub 解决办法吗？  &lt;/p&gt;</description>
      <author>rubyonme</author>
      <pubDate>Mon, 05 Mar 2012 11:02:21 +0800</pubDate>
      <link>https://ruby-china.org/topics/1618</link>
      <guid>https://ruby-china.org/topics/1618</guid>
    </item>
  </channel>
</rss>
