<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>hastings</title>
    <link>https://ruby-china.org/hastings</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>created_at 不自动保存原因</title>
      <description>&lt;h3 id="背景"&gt;背景&lt;/h3&gt;
&lt;p&gt;项目用的是一个复杂的数据库，这个数据库供不同语言，不同项目组使用。
在使用的过程中发现有些表创建记录时会自动保存 created_at 时间，有些不会，当时工期紧以为 created_at 字段赋值的方式解决这个问题。&lt;/p&gt;
&lt;h3 id="原因"&gt;原因&lt;/h3&gt;
&lt;p&gt;在对比过两种不同情况的表后发现，会自动保存的表，created_at 字段的默认值是 nil，不会自动保存的有其他默认值。通过调试后确认是 created_at 的默认值影响了自动填充的功能&lt;/p&gt;
&lt;h3 id="解决"&gt;解决&lt;/h3&gt;
&lt;p&gt;将不会自动填充 created_at 时间的表的 created_at 字段的默认值都改为 nil&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Tue, 29 Nov 2016 15:28:04 +0800</pubDate>
      <link>https://ruby-china.org/topics/31732</link>
      <guid>https://ruby-china.org/topics/31732</guid>
    </item>
    <item>
      <title>解决多数据库中 has_many 使用的一个坑</title>
      <description>&lt;h3 id="背景"&gt;背景&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;项目使用了多个数据库&lt;/li&gt;
&lt;li&gt;user 表在 system 库&lt;/li&gt;
&lt;li&gt;friends_relations 表在 thalassa 库&lt;/li&gt;
&lt;li&gt;thalassa 是默认库&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="目的"&gt;目的&lt;/h3&gt;
&lt;p&gt;实现查找某个用户的所有好友&lt;/p&gt;
&lt;h3 id="实现"&gt;实现&lt;/h3&gt;
&lt;p&gt;user model 的代码&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;System::User&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;System&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;BaseDb&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;abstract_class&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="n"&gt;establish_connection&lt;/span&gt; &lt;span class="ss"&gt;:system&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;table_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"system.users"&lt;/span&gt;

  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:friend_relationships&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:friends&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;through: :friend_relationships&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;source: :user&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;friend_relationships model 的代码&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FriendRelationship&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;

  &lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:class_name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"System::User"&lt;/span&gt;
  &lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:friend&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:class_name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"System::User"&lt;/span&gt;
&lt;span class="k"&gt;end&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="no"&gt;Mysql2&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;Table&lt;/span&gt; &lt;span class="s1"&gt;'system.friend_relationships'&lt;/span&gt; &lt;span class="n"&gt;doesn&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;exist&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;在 FriendRelationship 这个 model 中加上一行代码能解决这个问题&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FriendRelationship&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&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;table_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"thalassa.friend_relationships"&lt;/span&gt;

  &lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:class_name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"System::User"&lt;/span&gt;
  &lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:friend&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:class_name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"System::User"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>hastings</author>
      <pubDate>Wed, 17 Feb 2016 15:46:39 +0800</pubDate>
      <link>https://ruby-china.org/topics/29012</link>
      <guid>https://ruby-china.org/topics/29012</guid>
    </item>
    <item>
      <title>如何修改 Rails 默认的 created_at 和 updated_at</title>
      <description>&lt;p&gt;现在有个项目使用的数据是各个项目共用的，现在的数据库中使用的时间是 insert_time 和 update_time，数据类型也改了，存在数据库的时间是数字化的时间 (1444802209),请问有什么方法可以实现让 rails 在保存数据自动修改 insert_time 和 update_time，并且存储的时间也是数字化后的&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Wed, 14 Oct 2015 14:00:01 +0800</pubDate>
      <link>https://ruby-china.org/topics/27669</link>
      <guid>https://ruby-china.org/topics/27669</guid>
    </item>
    <item>
      <title>关于 psych 报错的一个解决过程</title>
      <description>&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/home/wumo/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:370:in `parse': (&amp;lt;unknown&amp;gt;): could not find expected ':' while scanning a simple key at line 29 column 1 (Psych::SyntaxError)
    from /home/wumo/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:370:in `parse_stream'
    from /home/wumo/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:318:in `parse'
    from /home/wumo/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/psych.rb:245:in `load'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这是执行项目的一个任务时报的错&lt;/p&gt;

&lt;p&gt;直接定位 psych.rb 的 370 行&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_stream&lt;/span&gt; &lt;span class="n"&gt;yaml&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;block_given?&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Psych&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Parser&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="no"&gt;Handlers&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;DocumentStream&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="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt; &lt;span class="n"&gt;yaml&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&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;parser&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt; &lt;span class="n"&gt;yaml&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;root&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;在这个方法里添加了两行代码打印 yaml 和 filename 两个参数&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_stream&lt;/span&gt; &lt;span class="n"&gt;yaml&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;
&lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="s2"&gt;"yaml: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;yaml&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="s2"&gt;"filename:&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;block_given?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;查看输出结果后发现是为 wumomq(我们自己写的一个 gem) 写的配置文件有问题。
最后发现出问题的配置代码是我从同事 qq 发送过来的记录中复制的代码有问题 (该问题无法通过 Sublime 看出)，在 vim 中看到出问题的配置代码无法高亮让我们知道了问题的所在。重新手动重写一次配置后，问题解决。&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Tue, 08 Sep 2015 14:07:16 +0800</pubDate>
      <link>https://ruby-china.org/topics/27236</link>
      <guid>https://ruby-china.org/topics/27236</guid>
    </item>
    <item>
      <title>has_one  方法的 scope 是否不接受其他参数</title>
      <description>&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Staff&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;
  &lt;span class="n"&gt;has_one&lt;/span&gt; &lt;span class="ss"&gt;:last_report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a_s&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="s2"&gt;"1111"&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;p&lt;/span&gt; &lt;span class="n"&gt;a_s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;report_type: &lt;/span&gt;&lt;span class="no"&gt;Report&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;report_types&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a_s&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="ss"&gt;class_name: &lt;/span&gt;&lt;span class="s1"&gt;'Report'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;打印 a_s 的时候出现的都是 staff 实例对象本身，查过 ruby on rails 的官方文档，其中有段代码为&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;has_one&lt;/span&gt; &lt;span class="ss"&gt;:dob&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Date.new(2000, 01, 01) &amp;gt; ?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dob&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;这个参数看来不像是实例对象，那推论 has_one 的 scope 应该是能接受其它参数的，可是为啥我的不行&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Mon, 15 Jun 2015 11:33:33 +0800</pubDate>
      <link>https://ruby-china.org/topics/26023</link>
      <guid>https://ruby-china.org/topics/26023</guid>
    </item>
    <item>
      <title>add_column_sql 的应用场景是啥</title>
      <description>&lt;p&gt;在查看 rails 的 api 时看到了 add_column_sql，它跟 add_column 的区别在哪里，哪种情况下它比 add_column 好使？&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Fri, 30 Jan 2015 17:15:59 +0800</pubDate>
      <link>https://ruby-china.org/topics/24029</link>
      <guid>https://ruby-china.org/topics/24029</guid>
    </item>
    <item>
      <title>求优化部门树形结构生成的代码的建议</title>
      <description>&lt;p&gt;有一张部门表，有 parent_id(上次部门的 id)
定义&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;:children&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="no"&gt;Department&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="ss"&gt;:children&lt;/span&gt;&lt;span class="p"&gt;]]]]]]])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;这段代码看一次揪心一次，太粗暴了&lt;/p&gt;

&lt;p&gt;如果我已经知道部门有多深（depth），如何生成.includes(arg) 中的 arg&lt;/p&gt;

&lt;p&gt;我的部门深度（depth）是每次部门的 parent_id 有变化的时候进行联动修改（修改自己和自己的 children），depth 的生成有什么更好的方法吗&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Tue, 20 Jan 2015 16:15:24 +0800</pubDate>
      <link>https://ruby-china.org/topics/23837</link>
      <guid>https://ruby-china.org/topics/23837</guid>
    </item>
    <item>
      <title>Rails 需要登录才能进行操作的 action 是否使用 collection 会好一点？</title>
      <description>&lt;p&gt;需要登录才能进行操作的 action 是否使用 collection 会好一点？&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Tue, 13 Jan 2015 16:21:38 +0800</pubDate>
      <link>https://ruby-china.org/topics/23710</link>
      <guid>https://ruby-china.org/topics/23710</guid>
    </item>
    <item>
      <title>一个纠结的 hash 问题</title>
      <description>&lt;p&gt;:047 &amp;gt; aa= [{a: 1, b:2}, {c: 2, b: 2}]
 =&amp;gt; [{:a=&amp;gt;1, :b=&amp;gt;2}, {:c=&amp;gt;2, :b=&amp;gt;2}] 
 :048 &amp;gt; bb = aa.clone
 =&amp;gt; [{:a=&amp;gt;1, :b=&amp;gt;2}, {:c=&amp;gt;2, :b=&amp;gt;2}] 
 :049 &amp;gt; c=aa.group_by{|item| item[:b]}
 =&amp;gt; {2=&amp;gt;[{:a=&amp;gt;1, :b=&amp;gt;2}, {:c=&amp;gt;2, :b=&amp;gt;2}]} 
 :050 &amp;gt; c[2]=c[2].map{|x| x[:a] = 3;x}
 =&amp;gt; [{:a=&amp;gt;3, :b=&amp;gt;2}, {:c=&amp;gt;2, :b=&amp;gt;2, :a=&amp;gt;3}] 
 :051 &amp;gt; aa
 =&amp;gt; [{:a=&amp;gt;3, :b=&amp;gt;2}, {:c=&amp;gt;2, :b=&amp;gt;2, :a=&amp;gt;3}] 
 :052 &amp;gt; bb
 =&amp;gt; [{:a=&amp;gt;3, :b=&amp;gt;2}, {:c=&amp;gt;2, :b=&amp;gt;2, :a=&amp;gt;3}] &lt;/p&gt;

&lt;p&gt;如何避免 bb 的值被改变？&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Thu, 08 Jan 2015 16:12:34 +0800</pubDate>
      <link>https://ruby-china.org/topics/23612</link>
      <guid>https://ruby-china.org/topics/23612</guid>
    </item>
    <item>
      <title>多重树形结构如何设计好</title>
      <description>&lt;p&gt;需要实现一个部门的树形结构列表，目前的设计是在该表上加一个 parent_id，有更好的办法吗&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Tue, 30 Dec 2014 13:51:12 +0800</pubDate>
      <link>https://ruby-china.org/topics/23474</link>
      <guid>https://ruby-china.org/topics/23474</guid>
    </item>
    <item>
      <title>使用 acts-as-taggable-on 时碰到的问题</title>
      <description>&lt;p&gt;When upgrading&lt;/p&gt;

&lt;p&gt;Re-run the migrations generator&lt;/p&gt;

&lt;p&gt;rake acts_as_taggable_on_engine:install:migrations&lt;/p&gt;

&lt;p&gt;It will create any new migrations and skip existing ones&lt;/p&gt;

&lt;p&gt;##Breaking changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ActsAsTaggableOn::Tag is not extend with ActsAsTaggableOn::Utils anymore.
Please use ActsAsTaggableOn::Utils instead&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;上面最后两行话我的理解是请在项目中使用 ActsAsTaggableOn::Utils，不要再用 ActsAsTaggableOn::Tag 
我的理解有没有错？&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Wed, 24 Dec 2014 16:55:44 +0800</pubDate>
      <link>https://ruby-china.org/topics/23385</link>
      <guid>https://ruby-china.org/topics/23385</guid>
    </item>
    <item>
      <title>iphone 的 safari 浏览器会自动调整页面的字体大小以适宜浏览？</title>
      <description>&lt;p&gt;如题&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Fri, 14 Feb 2014 17:39:23 +0800</pubDate>
      <link>https://ruby-china.org/topics/17262</link>
      <guid>https://ruby-china.org/topics/17262</guid>
    </item>
    <item>
      <title>rails 如何实现 socket 通信</title>
      <description>&lt;p&gt;想要实现一个功能，客户端发起一个请求，服务器分多次返回结果
不考虑客户端发起多次请求，请问如何实现&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Sat, 20 Jul 2013 18:11:18 +0800</pubDate>
      <link>https://ruby-china.org/topics/12638</link>
      <guid>https://ruby-china.org/topics/12638</guid>
    </item>
    <item>
      <title>MySQL 有没有办法从一个完整的 .sql 数据文件中将某张特定表导入数据库中</title>
      <description>&lt;p&gt;mysql 有没有办法从一个完整的.sql 数据文件中将某张特定表导入数据库中&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Fri, 12 Jul 2013 14:11:04 +0800</pubDate>
      <link>https://ruby-china.org/topics/12459</link>
      <guid>https://ruby-china.org/topics/12459</guid>
    </item>
    <item>
      <title>url 转码</title>
      <description>&lt;p&gt;key=Dior 迪奥 +3348900998223 
如何转换为
key=Dior%B5%CF%B0%C2%2B3348900998223 &lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Wed, 10 Jul 2013 16:45:00 +0800</pubDate>
      <link>https://ruby-china.org/topics/12399</link>
      <guid>https://ruby-china.org/topics/12399</guid>
    </item>
    <item>
      <title>rails 日期查询容易进入的误区</title>
      <description>&lt;p&gt;众所周知 mysql 的存储的数据中时间是跟当时时间差八小时的，我们正常引用时是不会出问题的，但当你试图对时间进行日期化查询时需要进行相应的处理
如我要查询今日的记录
错误的写法：Model.where("date(created_at) = ?",Date.today)
正确的写法：Model.where("date(date_add(created_at,interval 8 hour)) = ?",Date.today)
一般来说你对数据库进行时间查询，rails 会自动帮你作出处理，但这个处理只对时间形式的比较有效，对日期格式的比较是无效的。
以上面的写法为例，我要查询今天 (2013-4-13)7 点创建的一条数据
那么上面的查询语句就会变为
错误的写法：Model.where("date('2013-4-12 23:00:00') = ?", '2013-4-13') &amp;gt;&amp;gt; Model.where("'2013-4-12'= ?", '2013-4-13')
正确的写法：Model.where("date(date_add('2013-4-12 23:00:00',interval 8 hour)) = ?",'2013-4-13') &amp;gt;&amp;gt; Model.where("date('2013-4-13 7:00:00') = ?",'2013-4-13') =&amp;gt; Model.where("'2013-4-13'= ?", '2013-4-13')
综上所述，在对 mysql 进行日期查询时要作出相应的加 8 小时的处理&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Sat, 13 Apr 2013 09:47:12 +0800</pubDate>
      <link>https://ruby-china.org/topics/10149</link>
      <guid>https://ruby-china.org/topics/10149</guid>
    </item>
    <item>
      <title>rails 一个程序运行时能不能自己启动多个线程 </title>
      <description>&lt;p&gt;如题，如果可以的话能不能举个例子&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Thu, 11 Apr 2013 16:23:13 +0800</pubDate>
      <link>https://ruby-china.org/topics/10107</link>
      <guid>https://ruby-china.org/topics/10107</guid>
    </item>
    <item>
      <title>数据库表冲突</title>
      <description>&lt;p&gt;一个项目使用两个数据库，其中有两张分别处于不同数据库的同名表，请问如何避免冲突，又能正常调用两张表的数据
ps：两张表的表结构不同&lt;/p&gt;</description>
      <author>hastings</author>
      <pubDate>Thu, 28 Feb 2013 20:27:11 +0800</pubDate>
      <link>https://ruby-china.org/topics/9027</link>
      <guid>https://ruby-china.org/topics/9027</guid>
    </item>
  </channel>
</rss>
