<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>joezhang (joezhang)</title>
    <link>https://ruby-china.org/joezhang</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>Active Record Associations 的问题</title>
      <description>&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2016/df69aba7e5010cf25d2d18fcb10359e9.png!large" title="" alt=""&gt;&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;Physician&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:appointments&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:patients&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;through: :appointments&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Appointment&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:physician&lt;/span&gt;
  &lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:patient&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Patient&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:appointments&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:physicians&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;through: :appointments&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;关系如上，医生，病人，预约，很好理解，不过如果想设计 Physician 和 Patient 同属于一个表 User，应该怎么写呢？难道要用 Polymorphic Associations？感觉这样设计有点别扭。请指教。谢谢！&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;User&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:role&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;polymorphic: &lt;/span&gt;&lt;span class="kp"&gt;true&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Physician&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;as: :role&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Patient&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationRecord&lt;/span&gt;
  &lt;span class="n"&gt;has_many&lt;/span&gt; &lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;as: :role&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>joezhang</author>
      <pubDate>Fri, 16 Dec 2016 22:36:25 +0800</pubDate>
      <link>https://ruby-china.org/topics/31920</link>
      <guid>https://ruby-china.org/topics/31920</guid>
    </item>
    <item>
      <title>在线预约系统</title>
      <description>&lt;p&gt;正准备开发一个给美发美容店使用的在线预约系统，日历的话，可能打算使用 simple calendar，大家还有什么好的 gem 介绍吗？&lt;/p&gt;

&lt;p&gt;顺便问一下，有什么类似功能的网站可以参考一下的？&lt;/p&gt;

&lt;p&gt;谢谢。&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Thu, 06 Oct 2016 22:38:04 +0800</pubDate>
      <link>https://ruby-china.org/topics/31247</link>
      <guid>https://ruby-china.org/topics/31247</guid>
    </item>
    <item>
      <title>期待 Rails enum 的新功能</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;Conversation&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;enum&lt;/span&gt; &lt;span class="ss"&gt;status: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="ss"&gt;:active&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:archived&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;p&gt;Of course, you can also query them directly if the scopes don't fit your needs:&lt;/p&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;Conversation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;status: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:active&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:archived&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="no"&gt;Conversation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;where&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;not&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;status: :active&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;太需要这个 enum 功能了，不知道什么时候才能从 edge 更新到 Rails 新版本!
请教目前（Rails4.2.5）有什么简单而且高效的方法能实现以上功能，谢谢！&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Wed, 16 Dec 2015 11:55:06 +0800</pubDate>
      <link>https://ruby-china.org/topics/28406</link>
      <guid>https://ruby-china.org/topics/28406</guid>
    </item>
    <item>
      <title>Rails WEB/API 配置 Pundit 的问题？</title>
      <description>&lt;p&gt;练习一个 WEB/API 应用，试用 Pandit 做权限管理，请问为什么/controller/api/v1/users_controller.rb 和/controller/users_controller.rb 都指向同一个/policies/user_policy.rb 文件？怎么才能设置指向不同的文件？谢谢。
/controller/api/v1/base_controller.rb&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;Api::V1&lt;/span&gt;&lt;span class="ss"&gt;:BaseController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;Pundit&lt;/span&gt;
&lt;span class="o"&gt;......&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;/controller/api/v1/users_controller.rb&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;Api::V1&lt;/span&gt;&lt;span class="ss"&gt;:UsersController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;BaseController&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
    &lt;span class="vi"&gt;@users&lt;/span&gt; &lt;span class="o"&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;all&lt;/span&gt;
    &lt;span class="n"&gt;authorize&lt;/span&gt; &lt;span class="vi"&gt;@users&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;/controller/application_controller.rb&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;ApplicationController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;
  &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;Pundit&lt;/span&gt;
&lt;span class="o"&gt;......&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;/controller/users_controller.rb&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;UsersController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
    &lt;span class="vi"&gt;@users&lt;/span&gt; &lt;span class="o"&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;all&lt;/span&gt;
    &lt;span class="n"&gt;authorize&lt;/span&gt; &lt;span class="vi"&gt;@users&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;/policies/user_policy.rb&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;UserPolicy&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationPolicy&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Scope&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;Scope&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;resolve&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index?&lt;/span&gt; &lt;span class="kp"&gt;true&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;</description>
      <author>joezhang</author>
      <pubDate>Fri, 09 Oct 2015 22:51:59 +0800</pubDate>
      <link>https://ruby-china.org/topics/27609</link>
      <guid>https://ruby-china.org/topics/27609</guid>
    </item>
    <item>
      <title>［已解决］Ruby 字符串的处理方法？</title>
      <description>&lt;p&gt;举例说明，如果有以下字符串（......代表任意值）以;作为间隔，有没有什么好办法把其中重复的部分（AAA，CC）去掉？
"AAA;BBBB;AAA;CC;......;AAA;......;CC;..."
我目前的做法是遍历整个字符串，分解为数组［"AAA","BBBB","AAA","CC",......,"AAA",......,"CC",......] 然后遍历数组去掉重复的部分再组合成字符串，感觉这样的处理很不优雅。
谢谢大家！&lt;/p&gt;

&lt;p&gt;解决方案：
string.split(";").uniq.join(";")&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Wed, 27 May 2015 22:19:23 +0800</pubDate>
      <link>https://ruby-china.org/topics/25776</link>
      <guid>https://ruby-china.org/topics/25776</guid>
    </item>
    <item>
      <title>Ubuntu 14.04 升级引起的问题</title>
      <description>&lt;p&gt;本地使用 Vagrant 安装的 Ubuntu 14.04（ubuntu/trusty64 box）上面跑的 rails 环境。最近看到提示，使用 vagrant box update 升级到 v20150422.0.1 版本，之前使用得很正常的 Carrierwave，Jcrop，Minimagick 上传图片更改大小功能就不工作了（其他一切功能都正常，真是太奇怪了），查 Nginx log 也没提示错误，有人遇到这样的情况吗？
请大家帮帮忙？谢谢了！&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Fri, 01 May 2015 01:37:31 +0800</pubDate>
      <link>https://ruby-china.org/topics/25393</link>
      <guid>https://ruby-china.org/topics/25393</guid>
    </item>
    <item>
      <title>has_one 的疑问 </title>
      <description>&lt;p&gt;之前一直没用过 has_one，查看了 Rails 文档也搞不清楚。想请问一下为什么 User role 更改了却保存不了？谢谢了！&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;User&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;:profile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;dependent: :destroy&lt;/span&gt;
  &lt;span class="n"&gt;after_initialize&lt;/span&gt; &lt;span class="ss"&gt;:default_value&lt;/span&gt;
  &lt;span class="kp"&gt;private&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;default_value&lt;/span&gt;
      &lt;span class="vi"&gt;@profile&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;build_profile&lt;/span&gt;
      &lt;span class="vi"&gt;@profile.role&lt;/span&gt; &lt;span class="o"&gt;||=&lt;/span&gt; &lt;span class="s2"&gt;"User"&lt;/span&gt;
      &lt;span class="vi"&gt;@profile.avatar&lt;/span&gt; &lt;span class="o"&gt;||=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt; 
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Profile&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="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;irb&lt;span class="o"&gt;(&lt;/span&gt;main&lt;span class="o"&gt;)&lt;/span&gt;:001:0&amp;gt; User.first.profile
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;#&amp;lt;Profile id: nil, role: "User", avatar: "", user_id: 1, created_at: nil, updated_at: nil&amp;gt;&lt;/span&gt;
irb&lt;span class="o"&gt;(&lt;/span&gt;main&lt;span class="o"&gt;)&lt;/span&gt;:002:0&amp;gt; User.first.profile.role &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Admin"&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Admin"&lt;/span&gt;
irb&lt;span class="o"&gt;(&lt;/span&gt;main&lt;span class="o"&gt;)&lt;/span&gt;:003:0&amp;gt; User.first.profile.save
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;true
&lt;/span&gt;irb&lt;span class="o"&gt;(&lt;/span&gt;main&lt;span class="o"&gt;)&lt;/span&gt;:004:0&amp;gt; User.first.profile
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;#&amp;lt;Profile id: nil, role: "User", avatar: "", user_id: 1, created_at: nil, updated_at: nil&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;</description>
      <author>joezhang</author>
      <pubDate>Wed, 29 Apr 2015 21:46:27 +0800</pubDate>
      <link>https://ruby-china.org/topics/25376</link>
      <guid>https://ruby-china.org/topics/25376</guid>
    </item>
    <item>
      <title>项目上线前的重构、部署以及日后维护价格预算</title>
      <description>&lt;p&gt;个人项目的 DEMO 已经基本完成，正在准备商业计划书，打算做一个预算，价格包括重构（前端 CSS 美化）、部署以及日后维护费用，请有经验的朋友给点建议。
诚心请教，谢谢！&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Tue, 18 Nov 2014 01:31:11 +0800</pubDate>
      <link>https://ruby-china.org/topics/22728</link>
      <guid>https://ruby-china.org/topics/22728</guid>
    </item>
    <item>
      <title>[已解决] kickstarter.com 中的选择更新 Staff Picks 局部视图是怎么实现的？</title>
      <description>&lt;p&gt;请提供具体的实现思路，谢谢！
－－－－－－－－－－－－－－－－－－－－
找到了一个简单方法：
&lt;a href="https://coderwall.com/p/kqb3xq/rails-4-how-to-partials-ajax-dead-easy" rel="nofollow" target="_blank"&gt;https://coderwall.com/p/kqb3xq/rails-4-how-to-partials-ajax-dead-easy&lt;/a&gt;&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Wed, 05 Nov 2014 10:16:43 +0800</pubDate>
      <link>https://ruby-china.org/topics/22487</link>
      <guid>https://ruby-china.org/topics/22487</guid>
    </item>
    <item>
      <title>[已解决] Postgres 数据库错误？</title>
      <description>&lt;p&gt;以下代码在开发环境 sqlite3 数据库运行正常，在 Production 环境 Postgres9.3 数据库却出现错误，是什么原因呢？请指教，谢谢！&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;HomeController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
    &lt;span class="vi"&gt;@new_3_projects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Project&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:all&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="vi"&gt;@staff_pick_project&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Project&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;first&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;pre class="highlight shell"&gt;&lt;code&gt;App 18126 stdout: Processing by HomeController#index as HTML
App 18126 stdout: PG::InvalidTextRepresentation: ERROR:  invalid input syntax &lt;span class="k"&gt;for &lt;/span&gt;integer: &lt;span class="s2"&gt;"all"&lt;/span&gt;
App 18126 stdout: LINE 1: ...cts&lt;span class="s2"&gt;".* FROM "&lt;/span&gt;projects&lt;span class="s2"&gt;"  WHERE "&lt;/span&gt;projects&lt;span class="s2"&gt;"."&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="s2"&gt;" IN ('all', '--...
App 18126 stdout:                                                              ^
App 18126 stdout: : SELECT "&lt;/span&gt;projects&lt;span class="s2"&gt;".* FROM "&lt;/span&gt;projects&lt;span class="s2"&gt;"  WHERE "&lt;/span&gt;projects&lt;span class="s2"&gt;"."&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="s2"&gt;" IN ('all', '---
App 18126 stdout: :limit: 3
App 18126 stdout: ')  ORDER BY created_at DESC
App 18126 stdout: Completed 500 Internal Server Error in 1ms
App 18126 stdout:
App 18126 stdout: ActiveRecord::StatementInvalid (PG::InvalidTextRepresentation: ERROR:  invalid input syntax for integer: "&lt;/span&gt;all&lt;span class="s2"&gt;"
App 18126 stdout: LINE 1: ...cts"&lt;/span&gt;.&lt;span class="k"&gt;*&lt;/span&gt; FROM &lt;span class="s2"&gt;"projects"&lt;/span&gt;  WHERE &lt;span class="s2"&gt;"projects"&lt;/span&gt;.&lt;span class="s2"&gt;"id"&lt;/span&gt; IN &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'all'&lt;/span&gt;, &lt;span class="s1"&gt;'--...
App 18126 stdout:                                                              ^
App 18126 stdout: : SELECT "projects".* FROM "projects"  WHERE "projects"."id" IN ('&lt;/span&gt;all&lt;span class="s1"&gt;', '&lt;/span&gt;&lt;span class="nt"&gt;---&lt;/span&gt;
App 18126 stdout: :limit: 3
App 18126 stdout: &lt;span class="s1"&gt;')  ORDER BY created_at DESC):
App 18126 stdout:   app/controllers/home_controller.rb:3:in `index'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;解决方案：
rails 4 不推荐 find 了，推荐 where&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Fri, 31 Oct 2014 10:44:18 +0800</pubDate>
      <link>https://ruby-china.org/topics/22374</link>
      <guid>https://ruby-china.org/topics/22374</guid>
    </item>
    <item>
      <title>［已解决］Ubuntu 14.04 上使用 Nginx Passenger 部署 Ruby on Rails －“Could not find a JavaScript runtime” 错误</title>
      <description>&lt;p&gt;使用 vagrant 按照 Wiki 教程在 Ubuntu 14.04 上使用 Nginx Passenger 部署 Ruby on Rails，出现“Could not find a JavaScript runtime”错误，但是我已经安装了 Nodejs 了，请大家指点一下，搞了一天，这个坑实在是迈不过去了。&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vagrant@vagrant-ubuntu-trusty-64:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;add-apt-repository ppa:chris-lea/node.js
vagrant@vagrant-ubuntu-trusty-64:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
vagrant@vagrant-ubuntu-trusty-64:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;nodejs
vagrant@vagrant-ubuntu-trusty-64:~&lt;span class="nv"&gt;$ &lt;/span&gt;nodejs &lt;span class="nt"&gt;--version&lt;/span&gt;
v0.10.33
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;/var/log/nginx/error.log&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt; 2014-10-30 11:02:35.0093 1091/7f942a2f4700 Pool2/Implementation.cpp:287 &lt;span class="o"&gt;]&lt;/span&gt;: Could not spawn process &lt;span class="k"&gt;for &lt;/span&gt;application /vagrant/housing: An error occured &lt;span class="k"&gt;while &lt;/span&gt;starting up the preloader.
  Error ID: 75e8ef8e
  Error details saved to: /tmp/passenger-error-ATMG0r.html
  Message from application: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs &lt;span class="k"&gt;for &lt;/span&gt;a list of available runtimes. &lt;span class="o"&gt;(&lt;/span&gt;ExecJS::RuntimeUnavailable&lt;span class="o"&gt;)&lt;/span&gt;
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs/runtimes.rb:51:in &lt;span class="sb"&gt;`&lt;/span&gt;autodetect&lt;span class="s1"&gt;'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs.rb:5:in `&amp;lt;module:ExecJS&amp;gt;'&lt;/span&gt;
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/execjs-2.2.2/lib/execjs.rb:4:in &lt;span class="sb"&gt;`&lt;/span&gt;&amp;lt;top &lt;span class="o"&gt;(&lt;/span&gt;required&lt;span class="o"&gt;)&amp;gt;&lt;/span&gt;&lt;span class="s1"&gt;'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'&lt;/span&gt;  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in &lt;span class="sb"&gt;`&lt;/span&gt;block &lt;span class="k"&gt;in &lt;/span&gt;require&lt;span class="s1"&gt;'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'&lt;/span&gt;
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in &lt;span class="sb"&gt;`&lt;/span&gt;require&lt;span class="s1"&gt;'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/uglifier-2.5.3/lib/uglifier.rb:3:in `&amp;lt;top (required)&amp;gt;'&lt;/span&gt;
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in &lt;span class="sb"&gt;`&lt;/span&gt;require&lt;span class="s1"&gt;'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'&lt;/span&gt;
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in &lt;span class="sb"&gt;`&lt;/span&gt;each&lt;span class="s1"&gt;'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `block in require'&lt;/span&gt;
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in &lt;span class="sb"&gt;`&lt;/span&gt;each&lt;span class="s1"&gt;'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `require'&lt;/span&gt;
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler.rb:133:in &lt;span class="sb"&gt;`&lt;/span&gt;require&lt;span class="s1"&gt;'
  /vagrant/housing/config/application.rb:12:in `&amp;lt;top (required)&amp;gt;'&lt;/span&gt;
  /vagrant/housing/config/environment.rb:2:in &lt;span class="sb"&gt;`&lt;/span&gt;require&lt;span class="s1"&gt;'
  /vagrant/housing/config/environment.rb:2:in `&amp;lt;top (required)&amp;gt;'&lt;/span&gt;
  config.ru:3:in &lt;span class="sb"&gt;`&lt;/span&gt;require&lt;span class="s1"&gt;'
  config.ru:3:in `block in &amp;lt;main&amp;gt;'&lt;/span&gt;
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in &lt;span class="sb"&gt;`&lt;/span&gt;instance_eval&lt;span class="s1"&gt;'
  /home/vagrant/.rbenv/versions/2.1.4/lib/ruby/gems/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'&lt;/span&gt;
  config.ru:1:in &lt;span class="sb"&gt;`&lt;/span&gt;new&lt;span class="s1"&gt;'
  config.ru:1:in `&amp;lt;main&amp;gt;'&lt;/span&gt;
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="s1"&gt;'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `preload_app'&lt;/span&gt;
  /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in &lt;span class="sb"&gt;`&lt;/span&gt;&amp;lt;module:App&amp;gt;&lt;span class="s1"&gt;'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `&amp;lt;module:PhusionPassenger&amp;gt;'&lt;/span&gt;
  /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in &lt;span class="sb"&gt;`&lt;/span&gt;&amp;lt;main&amp;gt;&lt;span class="s1"&gt;'

[ 2014-10-30 11:02:35.0122 1091/7f941b7fe700 agents/HelperAgent/RequestHandler.h:2306 ]: [Client 20] Cannot checkout session because a spawning error occurred. The identifier of the error is 75e8ef8e. Please see earlier logs for details about the error.

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;</description>
      <author>joezhang</author>
      <pubDate>Thu, 30 Oct 2014 22:32:00 +0800</pubDate>
      <link>https://ruby-china.org/topics/22368</link>
      <guid>https://ruby-china.org/topics/22368</guid>
    </item>
    <item>
      <title>minimagick crop 截图不正常</title>
      <description>&lt;p&gt;开发环境：
MAC OS X 10.9.5
ruby '2.0.0'
gem 'rails', '4.0.1'
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.8.1'&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;convert &lt;span class="nt"&gt;-version&lt;/span&gt;
Version: ImageMagick 6.8.9-7 Q16 x86_64 2014-08-31 http://www.imagemagick.org
Copyright: Copyright &lt;span class="o"&gt;(&lt;/span&gt;C&lt;span class="o"&gt;)&lt;/span&gt; 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib freetype jng jpeg ltdl lzma png xml zlib
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;参照 Railscasts PRO #182 cropping images revised，可以正常更新，预览截图，但提交保存之后生成的 large 和 thumb 图片，是在原图基础上生成的，不是经过截图（crop）之后生成，应该是 img.crop 不正常。google 了一天也找不到答案。&lt;/p&gt;

&lt;p&gt;请有经验的同学帮帮忙指点一下。&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;ProjectPhotoUploader&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;CarrierWave&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Uploader&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;
  &lt;span class="kp"&gt;include&lt;/span&gt; &lt;span class="no"&gt;CarrierWave&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;MiniMagick&lt;/span&gt;
  &lt;span class="n"&gt;storage&lt;/span&gt; &lt;span class="ss"&gt;:file&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;store_dir&lt;/span&gt;
    &lt;span class="s2"&gt;"uploads/project/&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;cache_dir&lt;/span&gt;
    &lt;span class="s1"&gt;'uploads/tmp/project-cache'&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;extension_white_list&lt;/span&gt;
    &lt;span class="sx"&gt;%w(jpg jpeg gif png)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="c1"&gt;# Create different versions of your uploaded files:&lt;/span&gt;
  &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="ss"&gt;:large&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="ss"&gt;resize_to_limit: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;,&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;end&lt;/span&gt;

  &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="ss"&gt;:thumb&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="ss"&gt;:crop&lt;/span&gt;
    &lt;span class="n"&gt;process&lt;/span&gt; &lt;span class="ss"&gt;resize_to_fill: &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;crop&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;crop_x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;present?&lt;/span&gt;
      &lt;span class="n"&gt;resize_to_limit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;,&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="n"&gt;manipulate!&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;crop_x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;
        &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;crop_y&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;
        &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;crop_w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;
        &lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;crop_h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;
        &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;crop&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;x&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;+&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;+&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&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;</description>
      <author>joezhang</author>
      <pubDate>Wed, 01 Oct 2014 02:18:35 +0800</pubDate>
      <link>https://ruby-china.org/topics/21803</link>
      <guid>https://ruby-china.org/topics/21803</guid>
    </item>
    <item>
      <title>请推荐北美比较好的 Ruby and Rails 培训课程</title>
      <description>&lt;p&gt;请推荐北美比较好的 Ruby and Rails 培训课程（3~5 天的短训班），在加拿大的培训班更好。
谢谢。&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Wed, 10 Sep 2014 21:06:16 +0800</pubDate>
      <link>https://ruby-china.org/topics/21463</link>
      <guid>https://ruby-china.org/topics/21463</guid>
    </item>
    <item>
      <title>请问：用 MongoDB 写的应用有什么简单方法可以改写为 PG 版本？</title>
      <description>&lt;p&gt;谢谢！&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Thu, 10 Apr 2014 20:28:06 +0800</pubDate>
      <link>https://ruby-china.org/topics/18534</link>
      <guid>https://ruby-china.org/topics/18534</guid>
    </item>
    <item>
      <title>记录删除的处理方法</title>
      <description>&lt;h2 id="Model:"&gt;Model:&lt;/h2&gt;
&lt;p&gt;class User
include Mongoid::Document
field :name, type: String
has_many :topics, dependent: :destory
end&lt;/p&gt;

&lt;p&gt;class Topic
include Mongoid::Document
belongs_to :user
field :title, type: String
field :like_ids, type =&amp;gt; Array. :default =&amp;gt; []
end&lt;/p&gt;

&lt;p&gt;删除 user，那么 user 所创建的 topics 全部删除，这没什么问题。
但是在其他 user 创建的 topic 中，like_ids 保存有被删除 user 的 id，应该怎么处理比较方便？&lt;/p&gt;

&lt;p&gt;目前我能想出的苯的方法是删除 user 前，检索一遍所有其他 user 的 like_ids Array 中是否有被删除的 user.id，调用 pull () 在 like_ids Array 中去掉被删除的 user.id。但是如果日后 user 和 topic 记录多了之后，就会比较影响性能。&lt;/p&gt;

&lt;p&gt;请指点一下，谢谢。&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Thu, 23 Jan 2014 23:42:36 +0800</pubDate>
      <link>https://ruby-china.org/topics/16961</link>
      <guid>https://ruby-china.org/topics/16961</guid>
    </item>
    <item>
      <title>Rails check_box 的疑问</title>
      <description>&lt;p&gt;Ruby2.0, Rails 4.0.1, MongoDB and Mongoid&lt;/p&gt;
&lt;h2 id="Model:"&gt;Model:&lt;/h2&gt;
&lt;p&gt;class User
  include Mongoid::Document
  field :name, type: String
  field :delete, type: Boolean, :default =&amp;gt;false
  def self.delete_users
    where(delete: true)
  end
end&lt;/p&gt;
&lt;h2 id="new.html.erb"&gt;new.html.erb&lt;/h2&gt;
&lt;p&gt;...
&amp;lt;%= f.check_box :delete, :checked=&amp;gt;true %&amp;gt;
...
保存的结果是...,"delete":"1"... &lt;/p&gt;

&lt;p&gt;如果改为
...
&amp;lt;%= f.check_box :delete, :checked=&amp;gt;true, true, false %&amp;gt;
...
保存的结果是...,"delete":"true"...&lt;/p&gt;

&lt;p&gt;所以当查询 User.delete_users，没有返回值。请问有什么方法可以转换保存为（...,"delete":true...）？
在网上搜寻了一番也没找到解决办法，请大家指点一下。&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Tue, 21 Jan 2014 23:03:56 +0800</pubDate>
      <link>https://ruby-china.org/topics/16914</link>
      <guid>https://ruby-china.org/topics/16914</guid>
    </item>
    <item>
      <title>如何学习 JRuby？</title>
      <description>&lt;p&gt;年底前开始学 Ruby on Rails，目前由于工作需要，准备开始学习 JRuby（有实际的开发和部署环境，可以学以致用），除了看官方文档之外，应该如何快速学习提高？
请大家指点一下，谢谢了。&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Thu, 09 Jan 2014 23:56:18 +0800</pubDate>
      <link>https://ruby-china.org/topics/16715</link>
      <guid>https://ruby-china.org/topics/16715</guid>
    </item>
    <item>
      <title>Heroku 连接 MongoHQ 的问题</title>
      <description>&lt;p&gt;最近刚开始学 Rails，尝试使用 Heroku 连接 MongoHQ，按照以下介绍：
&lt;a href="http://support.mongohq.com/tutorials/rails-4-mongoid-heroku.html" rel="nofollow" target="_blank"&gt;http://support.mongohq.com/tutorials/rails-4-mongoid-heroku.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;顺利部署到 Heroku，但是数据库好像连接不上，加上了 MONGOHQ_URL 设置也没效果。
$ heroku config:add MONGOHQ_URL=mongodb://user:pass@server.mongohq.com:port/db_name&lt;/p&gt;

&lt;p&gt;请指导一下，非常感谢。&lt;/p&gt;</description>
      <author>joezhang</author>
      <pubDate>Sat, 04 Jan 2014 11:43:30 +0800</pubDate>
      <link>https://ruby-china.org/topics/16615</link>
      <guid>https://ruby-china.org/topics/16615</guid>
    </item>
  </channel>
</rss>
