<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>rails on 老王的日志</title>
    <link>http://superwf.github.io/categories/rails/</link>
    <description>Recent content in rails on 老王的日志</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-CN</language>
    <lastBuildDate>Mon, 14 Apr 2014 05:14:36 +0000</lastBuildDate>
    
	<atom:link href="http://superwf.github.io/categories/rails/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>yeoman &amp; rails整合开发</title>
      <link>http://superwf.github.io/p803/</link>
      <pubDate>Mon, 14 Apr 2014 05:14:36 +0000</pubDate>
      
      <guid>http://superwf.github.io/p803/</guid>
      <description>grunt serve的测试环境用的9000端口，向后台发起的默认ajax也是9000
为了与rails整合，在app.coffee里加上
然后在所有需要请求的url之前都加上 rails + ‘/user.json’
这里还涉及到一个ajax跨域的事，得在rails的controller里设置
实际部署的时候可以去掉这个，在nginx里加这个header，把*改成相对应的域名。
后来发现加这个不灵
http://serverfault.com/questions/418709/nginx-add-header-for-a-50-page
401状态下无法自定义header，需要用
http://wiki.nginx.org/HttpHeadersMoreModule
这仅仅因为在开发环境下grunt serve和rails需要用到不同的域，至少需要不同端口，实际部署的时候应该是用不到这些。
干了两天之后各种问题导致各种手动修改补丁，最后还是用nginx配置这些比较合适，在开发时就干脆把这两个后台都整合到一个域名里，也消除了跨域的问题。
nginx配置
  </description>
    </item>
    
    <item>
      <title>form_builder与render partial block</title>
      <link>http://superwf.github.io/p659/</link>
      <pubDate>Sun, 29 Sep 2013 08:07:10 +0000</pubDate>
      
      <guid>http://superwf.github.io/p659/</guid>
      <description>最近想从bootstrap2升级到3，发现类名的变化很多。
之前的很多class都写在模板里了，看来还得搞统一方法调用，或者统一模板调用。
先想到用form_builder，但后来发现form_builder不支持form_tag，而且只能影响from里的input的生成，不能在form本身加一些属性什么的。
然后看action_view里的render，以前知道render后面是可以接一个block的。
但实际用上才知道，render后面带的block对与partial来说没作用，只有在render layout: ‘xxxx’时才有用。
本来还打算用一个partial的模板，render ‘xxx’ do |f|这样把一个block传进去，然后在里面用simple_form_for xxxx do |f|里面处理这个block
但是别说带参数的模板了，反正是传不进去。
最后不得已用一个helper写了一个，里面还得写字符串变量相加这种不太好看的东西。</description>
    </item>
    
    <item>
      <title>end of file reached</title>
      <link>http://superwf.github.io/p657/</link>
      <pubDate>Thu, 26 Sep 2013 05:58:29 +0000</pubDate>
      
      <guid>http://superwf.github.io/p657/</guid>
      <description>今天修改一个页面，一刷新就出错说 end of file reached
这个错误莫名其妙，出在一个 = include_javascript_tag :priemrs的行
把这样注释掉就好了，但是js就没了。
于是去这个coffee文件里看了半天也没debug出什么错误。
后来把tmp/cache/assets里的缓存清空搞定。</description>
    </item>
    
    <item>
      <title>activeresource4.0 paginate</title>
      <link>http://superwf.github.io/p645/</link>
      <pubDate>Thu, 05 Sep 2013 01:58:55 +0000</pubDate>
      
      <guid>http://superwf.github.io/p645/</guid>
      <description>rails4之后，把activeresource踢出去了，大概更新了里面的什么，原来的active-resource-pagination失效了，想查查新的activeresource的api，点过去跳转到rails的api，但rails的api里又没有…
http://yetimedia.tumblr.com/post/35233051627/activeresource-is-dead-long-live-activeresource
现在最新的说明也就是这个了。弄了半天，照着这个自己弄了个分页，collection_parser这个很管用。
自己弄了类 WillPaginateTotalPages，名字随便起就行。
这样就可以将current_page和total_page传递过来
服务端的api需要写成
WillPaginate::Collection里的initialize接收的参数和collection_parser需求的不一致，要不就能直接用
activeresource的has_many和belongs_to关系已经大概有了，但是都是针对activeresource的，如果一个远程的activeresource的模型，关联了一些本地的activerecord的数据，这种对应关系看来还是得手动写。比如一个远程客户库的客户，会关联当前程序中的订单。希望将来activeresource的has_many这种能加后面的key参数指定关联对象是activeresource还是activerecord或者是别的mongoid什么的。但是这种关联的话joins什么的就不要想了。</description>
    </item>
    
    <item>
      <title>mina rvmsudo</title>
      <link>http://superwf.github.io/p638/</link>
      <pubDate>Fri, 30 Aug 2013 02:15:20 +0000</pubDate>
      
      <guid>http://superwf.github.io/p638/</guid>
      <description>最近面试了一位同行，听说用mina代替capistrona。
用了一下，mina的用法也差不多。
不过后来卡在了需要远程执行一些sudo的命令上。服务器上的ruby使用rvm装的，rake，ruby这些的路径都是从/usr/bin/env 执行的。visudo里面不好制定这些程序的路径。
后来发现用rvmsudo这个东西，写rvm的人还真是体贴，这种配套的东西都也出来了~~~
本地rvmsudo还行，但是远程就报错了
sudo: no tty present and no askpass program specified
http://blog.csdn.net/buptxx/article/details/8241997
搜到这个，visudo加上Defaults visiblepw</description>
    </item>
    
    <item>
      <title>最近改了很多模型</title>
      <link>http://superwf.github.io/p631/</link>
      <pubDate>Mon, 19 Aug 2013 03:51:45 +0000</pubDate>
      
      <guid>http://superwf.github.io/p631/</guid>
      <description>之前因为受重构前程序的错误思维导向，弄了很多多余的模型出来，导致有一些has_one关系的表现在看来完全没有必要独立出来。
如果某个模型的has_one 子表数据，可能存在也可能不会存在，则这个has_one就可以独立设置model，否则就直接作为当前模型的属性存在。否则这种has_one关系过多，导致关系复杂，更麻烦的是查询的复杂和效率的降低。
而且还有些模型完全可以用一个polymorhpic的单一模型代替。</description>
    </item>
    
    <item>
      <title>rspec request redirect_back</title>
      <link>http://superwf.github.io/p628/</link>
      <pubDate>Fri, 09 Aug 2013 04:53:07 +0000</pubDate>
      
      <guid>http://superwf.github.io/p628/</guid>
      <description>(ActionController::RedirectBackError) “No HTTP_REFERER was set in the request to this action, so redirect_to :back could not be called successfully. If this is a test, make sure to specify
之前一直没写request的测试，最近升级rails4.0出错的地方挺多，决定还是把这方面的测试弄上好踏实点。
当测试请求一个页面redirect_to :back时，可以用referer参数模拟，要放在模拟表单参数的后面。如果没有表单的参数也需要用一个{}来占位。
put “/post/1”, post: {title: ‘abc’}, {referer: ‘/posts’}</description>
    </item>
    
    <item>
      <title>今天第一次写gem的系统命令</title>
      <link>http://superwf.github.io/p576/</link>
      <pubDate>Wed, 24 Jul 2013 08:24:34 +0000</pubDate>
      
      <guid>http://superwf.github.io/p576/</guid>
      <description>看我的gem的gemspec文件里有spec.executables 的字样，就放了一个/bin文件夹在里面，把自己常用的几个脚本放进去了。
rake install 之后倒是在系统搜索路径里有这个命令了，但是执行后报错说语法错误。
看了一下安装进去的文件发现，是按ruby语法执行的，原来的bash脚本肯定会报错。
也好，用ruby语法写比bash舒服多了。</description>
    </item>
    
    <item>
      <title>rails 4.0.0发布，版本强迫更新症发作</title>
      <link>http://superwf.github.io/p545/</link>
      <pubDate>Thu, 04 Jul 2013 01:37:32 +0000</pubDate>
      
      <guid>http://superwf.github.io/p545/</guid>
      <description>非技术文，记录一下。
今看rails api的文档一个链接点不开了，一刷新发现版本变了。
just go 4.0
6月25日就发布了，我落后了…
之前于工教的mfs的事先暂缓一下。
change logs
controller里的params不能直接用了，需要require 后在permit
activerecord的update_attributes 加了个简便的alias — update
migration里的定义可以直接加index，不用再之后add_index了，如t.string :name, index: true
也可以直接t.index :name
join table有了自己的create_join_table
所有controller里的before_filter都改成before_action
after 和 around的也同改。
所有controller里的params给model的赋值也都得先require &amp;amp; permit
所有model的scope 改 -&amp;gt; {where xxx}
has_many的restrict改成restrict_with_error，连带着controller里的destroy也不用rescure了，直接用flash显示错误就行。
升级到4.0不像2升到3变化那么大，也没有3.0到3.1的时候加了assets这些东西，大概算是平滑过度。</description>
    </item>
    
    <item>
      <title>em-websocket</title>
      <link>http://superwf.github.io/p527/</link>
      <pubDate>Tue, 25 Jun 2013 02:54:36 +0000</pubDate>
      
      <guid>http://superwf.github.io/p527/</guid>
      <description>第一次做websocket的东西。
eventmachine和原来习惯的顺序执行思路的编程相差很多。先是在
本以为客户端会每两秒收到一次信息，但是结果是等3次都执行完，server一次性发送全部信息给client
后来看eventmachine的api发现TickLoop这个循环可以非阻塞的立即发送信息给client，将普通循环替换成
但是由于是非阻塞，tick_loop后面的代码会立即执行，而不管tick_loop，导致在tick_loop中的变量和后面变量不一致。
开始还以为在tick_loop中生成了新的线程，复制了局部变量，但是debug变量的object_id后发现是没变的，后来显示前后的时间才发现了执行的顺序不对劲。
再后来，发现在tick_loop中，ws.send 也是每次循环之后一起发送，而不是按照先后顺序调用的发送，比如
在server的两次puts 相差1秒，但是在client的接收确实同时接收，没有时间差。
最后试来试去，发现在EM.defer里用常规的循环，可以实现我想要的效果。在defer里用tick_loop不能。
这样client可以按照时间顺序接收到消息。
后来想想，ws这中模式，应大有作为，替换掉原来的http开发模式，使web程序变得更有交互性。大概主要的交互方式有两种，一种是直接推送js，让浏览器执行更新数据。
一种是推送json，里面有需要调用的函数，与该函数的参数然后eval执行。应该是后种更好一些，交互的数据量更小但需要前台有丰富的接口支持。大概这类的前台框架国外已经有了吧我想。
不过当前的开发主流框架还没有跟进到这个地步，web的开发流程与开发者也需要很大的逻辑转变。</description>
    </item>
    
    <item>
      <title>chrome文件下载content-disposition错误</title>
      <link>http://superwf.github.io/p520/</link>
      <pubDate>Thu, 20 Jun 2013 07:06:45 +0000</pubDate>
      
      <guid>http://superwf.github.io/p520/</guid>
      <description>碰到个怪问题。文件下载不能。chrom报错说多个content-disposition重复。
看后台日志全都显示正常，后来发现只有今天新上传的几个文件下载有问题。用火狐试了一下能下载。发现这几个文件的文件名里都有逗号。所以在下载时指定的content-disposition里的filename里的内容被逗号分割了。在里面把文件名用单引号引起来就好了。</description>
    </item>
    
    <item>
      <title>关于unicorn的平滑重启</title>
      <link>http://superwf.github.io/p492/</link>
      <pubDate>Tue, 04 Jun 2013 07:42:43 +0000</pubDate>
      
      <guid>http://superwf.github.io/p492/</guid>
      <description>http://ruby-china.org/topics/35
今天偶然看到了这篇
看到unicorn有个平滑重启，但是按这个
preload_app false的配置，好像不能管用，还报很多错
改回true之后倒是能用
实验了一下，是可以的
kill -USR2 之后生成新pid但是老pid.oldbin需要手动kill一下
unicorn的说明里写等新进程载入完毕之后再kill老进程。</description>
    </item>
    
    <item>
      <title>accepts_nested_attributes_for validates_presence_of</title>
      <link>http://superwf.github.io/p408/</link>
      <pubDate>Wed, 24 Apr 2013 02:50:38 +0000</pubDate>
      
      <guid>http://superwf.github.io/p408/</guid>
      <description>用了accepts_nested_attributes_for之后
在子模型中用了验证父模型的presence: true
但是在关联创建的时候，父模型数据还没有save的时候总是不能通过验证。
之前都是干脆取消了 presence的验证。
后来想想不对劲，验证必须严格。
参照
http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html#label-Validating+the+presence+of+a+parent+model
这时候 has_many 和 belongs_to的
inverse_of 参数就有用了。
之前这个参数的说明我一直没理解。现在总算用上了一回。</description>
    </item>
    
    <item>
      <title>关于belongs_to的through</title>
      <link>http://superwf.github.io/p405/</link>
      <pubDate>Mon, 22 Apr 2013 09:47:32 +0000</pubDate>
      
      <guid>http://superwf.github.io/p405/</guid>
      <description>has_one和has_many都有through 的参数。
本来belongs_to也应该有。
比如
order belongs_to client
client belongs_to company
so
order belongs_to company
逻辑上比较容易这么想。
但是belongs_to 没有越级的这种优惠。
根据stackoverflow上有人说，belongs_to 认为当前模型一定会有一个外键与所属的表相关连。所有没有越级through参数。
如果想简单的实现
在order里定义
或者
delegate :company, to: :client
都行
但是这样的话在联合搜索的时候，不能通过模型关联自动生成联合查询的sql
例如
后来我采用的方式是在orders上增加company_id字段，在client的更新的hook上加上更新所有orders的company_id，为了搜索的方便，增加了更新的麻烦。</description>
    </item>
    
    <item>
      <title>activeresource的pagination</title>
      <link>http://superwf.github.io/p403/</link>
      <pubDate>Wed, 10 Apr 2013 06:11:14 +0000</pubDate>
      
      <guid>http://superwf.github.io/p403/</guid>
      <description>use this gem
active-resource-pagination
就是activeresource没有activerecord那样方便的 relation关系，用着觉得不是很爽</description>
    </item>
    
    <item>
      <title>在activeresource中使用http-digest-authentication认证</title>
      <link>http://superwf.github.io/p400/</link>
      <pubDate>Wed, 03 Apr 2013 02:01:09 +0000</pubDate>
      
      <guid>http://superwf.github.io/p400/</guid>
      <description>用https弄了半天，好像自己生成的证书不好用，总是不能通过验证
就改用另一种比http basic认证安全一些的http-digest
这种方法rails的api中没有提如何与activeresource配合使用，参照如下即可。
https://rails.lighthouseapp.com/projects/8994/tickets/3335-http-digest-authentication-for-activeresource</description>
    </item>
    
    <item>
      <title>rails在test下使用memory引擎</title>
      <link>http://superwf.github.io/p388/</link>
      <pubDate>Tue, 19 Mar 2013 06:25:16 +0000</pubDate>
      
      <guid>http://superwf.github.io/p388/</guid>
      <description>一直用rspec和database_cleaner进行测试，表一多，每个测试都要truncate所有的table，每个it都要一秒多，硬盘卡拉卡拉的巨响不说，这样下来一个模型测试下来就得好几分钟。
每次一测试都可以去上个厕所什么的再回来。
终于想到了，把test时用的db换成memory引擎的。
google了一下，看有用sqlite的memory引擎的，不过mysql的也应该差不多。
首先要将所有migration里的text 和 blob的字段换成 string的，因为memory不支持这两个类型。当然测试样例里如果要测试这些字段，也别放超过255个字符的就可以。
然后在db/seed.rb文件里加上
db = ::Atable.connection
if ::Rails.env.test?
tables = db.tables
tables.delete ‘schema_migrations’
tables.each do |t|
db.execute “ALTER TABLE #{t} ENGINE= MEMORY”
end
exit
end
再执行rake db:seed RAILS_ENV=test
将所有表转换为memory
马上测试。原来要好几分钟的测试，现在就一两秒完成, done
补充，后来我把这个功能单写了一个gem，叫convert_memory_engine
https://github.com/superwf/convert_memory_engine
也可以gem install convert_memory_engine</description>
    </item>
    
    <item>
      <title>部署新项目后，doorkeeper总是不能redirect到正确的url上</title>
      <link>http://superwf.github.io/p382/</link>
      <pubDate>Thu, 14 Mar 2013 06:40:38 +0000</pubDate>
      
      <guid>http://superwf.github.io/p382/</guid>
      <description>今天大概折腾了大半天，新项目部署之后用doorkeeper授权之后总是跳转到之前开发的网址url上。
改了很多配置，折腾devise什么的配置，最后发现是nginx的配置上的redirect的网址绑定了原来的地址。</description>
    </item>
    
    <item>
      <title>ruby2.0速度快了</title>
      <link>http://superwf.github.io/p378/</link>
      <pubDate>Wed, 13 Mar 2013 07:12:14 +0000</pubDate>
      
      <guid>http://superwf.github.io/p378/</guid>
      <description>今天rvm上了一下2.0.0，然后重新bundle了一下项目重新启动，明显感觉重启速度快了一些，不是错觉。非常好！</description>
    </item>
    
    <item>
      <title>ruby读取二进制文件，activeresource的上传</title>
      <link>http://superwf.github.io/p374/</link>
      <pubDate>Mon, 18 Feb 2013 06:13:34 +0000</pubDate>
      
      <guid>http://superwf.github.io/p374/</guid>
      <description>今天用到activeresource上传文件的功能，不能实现，因为activeresource好像还没有原生实现文件上传功能。
改用rest-client代替了，也没多写多少。
还有就是在windows下需要指定二进制模式，File.open(path, binmode: true)</description>
    </item>
    
    <item>
      <title>passenger upstream prematurely closed connection while reading response header from upstream</title>
      <link>http://superwf.github.io/p369/</link>
      <pubDate>Tue, 08 Jan 2013 03:11:40 +0000</pubDate>
      
      <guid>http://superwf.github.io/p369/</guid>
      <description>这两天弄passenger
一开始编译好之后，一配置，马上就运行出来了，觉得十分容易。
第二天再配置的时候，就出502 Bad Gateway
nginx erro log里显示
upstream prematurely closed connection while reading response header from upstream
google了很多结果，竟然还有时不时发生这种情况，大部分都能正常运行的例子。
https://groups.google.com/forum/?fromgroups=#!topic/phusion-passenger/kcWP9T8uksg
后来也没看到彻底的解决。先还是用unicorn好了，这个调试还熟悉。</description>
    </item>
    
    <item>
      <title>mongoid升级3.0之后出现undefined method `database’ for Mongoid:Module (NoMethodError)</title>
      <link>http://superwf.github.io/p365/</link>
      <pubDate>Mon, 07 Jan 2013 06:20:29 +0000</pubDate>
      
      <guid>http://superwf.github.io/p365/</guid>
      <description>mongoid升级3.0之后出现undefined method `database’ for Mongoid:Module (NoMethodError)
先是把mongoid版本制定 ~&amp;gt;2.0之后，确实可以正常使用，就确定是mongoid升级之后的方法名变了。
搜到了这个，按之操作解决问题。
http://stackoverflow.com/questions/12019922/config-carrierwave-with-mongoid-gridfs</description>
    </item>
    
    <item>
      <title>jquery_ujs在method为put或delete的时候加入参数</title>
      <link>http://superwf.github.io/p361/</link>
      <pubDate>Fri, 21 Dec 2012 06:17:28 +0000</pubDate>
      
      <guid>http://superwf.github.io/p361/</guid>
      <description>当需要在点击删除或更新按钮的同时，弹出输入框输入原因并记录原因的时候。
就需要在提交的同时增加虚拟表单中的数据。
一开始不知道就直接加到url上了，但是后来觉得太难看，照着一下这个设置可以
但是只针对有remote: true时起作用。
https://github.com/rails/jquery-ujs/issues/168</description>
    </item>
    
    <item>
      <title>prawn里内嵌png</title>
      <link>http://superwf.github.io/p345/</link>
      <pubDate>Fri, 19 Oct 2012 03:22:36 +0000</pubDate>
      
      <guid>http://superwf.github.io/p345/</guid>
      <description>prawn里内嵌png
在photoshop里导出png时，必须选择无交错，否则prawn里会报错，不能嵌入图片。</description>
    </item>
    
    <item>
      <title>rspec中用了stub之后总有报错 wrong number of arguments(1 for 0)</title>
      <link>http://superwf.github.io/p342/</link>
      <pubDate>Thu, 27 Sep 2012 03:19:53 +0000</pubDate>
      
      <guid>http://superwf.github.io/p342/</guid>
      <description>弄了好几个钟头，一开始用rspec -b参数看trace信息还以为是rspec版本的问题。
弄到后来发现一个model的属性叫method弄得出错。
属性名改为method_name之后就好了，method的名字不能用，是我疏忽了。</description>
    </item>
    
    <item>
      <title>rspec中counter_cache不自动更新的问题</title>
      <link>http://superwf.github.io/p339/</link>
      <pubDate>Wed, 05 Sep 2012 01:42:28 +0000</pubDate>
      
      <guid>http://superwf.github.io/p339/</guid>
      <description>rspec时，counter_cache的数字没有自动更新。
发现因为缓存，reload一下就好了。
而且FactoryGirl.craete 所创建的对象不能出发 counter_cache自动更新功能，还是必须用model自己的create方法。</description>
    </item>
    
    <item>
      <title>nginx https fastcgi</title>
      <link>http://superwf.github.io/p313/</link>
      <pubDate>Fri, 27 Jul 2012 09:04:19 +0000</pubDate>
      
      <guid>http://superwf.github.io/p313/</guid>
      <description>upstream unicorn-ends{
server unix:/xxxxxx/unicorn.sock;
}
map $scheme $fastcgi_https {
default on;
https on;
}
server {
#listen 80;
listen 443 default ssl;
server_name www.example.com;
client_max_body_size 50m;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param HTTPS on;
#include /etc/nginx/fastcgi_params;
#log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
access_log /var/log/nginx/user.log;
root /path/public;
ssl on;
ssl_certificate /etc/nginx/keys/server.crt;
ssl_certificate_key /etc/nginx/keys/server.key;
ssl_protocols SSLv3 SSLv2 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
# serve static files
# Main location
location / {</description>
    </item>
    
    <item>
      <title>mini_magick resize图片，不保持长宽比</title>
      <link>http://superwf.github.io/p308/</link>
      <pubDate>Wed, 04 Jul 2012 08:24:39 +0000</pubDate>
      
      <guid>http://superwf.github.io/p308/</guid>
      <description>需要将图片更改成固定尺寸。
github上关于mini_magick的说明全是 resize ‘100×100’ 这样的例子
都是会自动保持长宽比。
但我要的是不要保持长宽比的，找了半天愣是没发现。
后来看imagemagick文档发现参数中用 ‘100×100!’
加上个!，就强制不保持长宽比了。</description>
    </item>
    
    <item>
      <title>过滤html tag外内容的正则</title>
      <link>http://superwf.github.io/p298/</link>
      <pubDate>Mon, 25 Jun 2012 01:57:05 +0000</pubDate>
      
      <guid>http://superwf.github.io/p298/</guid>
      <description>上礼拜上班最后俩钟头写的一个，大概是我用上过最复杂的正则了
rails里用的，需要把所有html标签外的的数字与英文都替换成_…_包裹的内容。
prawn里替换字体用的，领导希望所有英文用times new roman字体显示。其他中文用宋体，prawn里没找着这种混合设置，只能想到用正则筛。
args[0].gsub!(/(?&amp;lt;!&amp;lsquo;&amp;lt;&amp;rsquo;)([a-z0-9]+)(?![^&amp;gt;]*?[&amp;gt;])/i, ‘\1‘) if args[0].is_a? String
str.gsub!(/(?&amp;lt;=&amp;lt;([^&amp;gt;])&amp;gt;).*?([a-z0-9]+).*?(?=&amp;lt;/\1&amp;gt;)/i, ‘\2‘)
如果在零宽度正回顾后发断言中使用了数量匹配，就报错。比如
str.gsub!(/(?&amp;lt;=&amp;lt;([^&amp;gt;]+)&amp;gt;).*?([a-z0-9]+).*?(?=&amp;lt;/\1&amp;gt;)/i, ‘\2‘)
但是匹配固定数量没问题，比如
str.gsub!(/(?&amp;lt;=&amp;lt;([^&amp;gt;]{1})&amp;gt;).*?([a-z0-9]+).*?(?=&amp;lt;/\1&amp;gt;)/i, ‘\2‘)
网上都这么写没错，可能ruby的有些特殊，还是bug?
http://stackoverflow.com/questions/3479131/problem-with-quantifiers-and-look-behind
如是说，说不止ruby一个不支持在反向回顾中支持数量匹配的。</description>
    </item>
    
    <item>
      <title>mongodb assertion: 13325</title>
      <link>http://superwf.github.io/p295/</link>
      <pubDate>Fri, 15 Jun 2012 03:01:10 +0000</pubDate>
      
      <guid>http://superwf.github.io/p295/</guid>
      <description>打算把文件上传用mongodb的gridfs代替原来的文件系统存储。
弄了半天carrierwave-mongoid
文件是存进去了，但是读不出来。
在命令行下用mongofiles -d databasename list能看到文件
mongofiles -d databasename get uploads/1022/note.png就报错误
assertion: 13325 couldn’t open file: uploads/1022/note.png
搜了有人说是权限问题，搞了半天发现get带路径的文件名的时候，必须在当前文件夹下创建该目录结构。
也就是说如果要get uploads/1022/note.png
就必须先创建 uploads/1022这个文件夹。</description>
    </item>
    
    <item>
      <title>一个建立rails新程序的向导</title>
      <link>http://superwf.github.io/p289/</link>
      <pubDate>Tue, 05 Jun 2012 00:53:00 +0000</pubDate>
      
      <guid>http://superwf.github.io/p289/</guid>
      <description>rails new rails3-devise-rspec-cucumber -m https://raw.github.com/RailsApps/rails3-application-templates/master/rails3-devise-rspec-cucumber-template.rb</description>
    </item>
    
    <item>
      <title>incompatible character encodings: UTF-8 and ASCII-8BIT</title>
      <link>http://superwf.github.io/p274/</link>
      <pubDate>Fri, 20 Apr 2012 03:46:10 +0000</pubDate>
      
      <guid>http://superwf.github.io/p274/</guid>
      <description>有一个页面，上传csv并解析后存如数据库，如果解析格式错误则render之前的页面提示错误。
有个问题，上传文件中的字符出错后，如果该字符中包含非ascii字符页面就会报错
incompatible character encodings: UTF-8 and ASCII-8BIT
网上说了好多都说数据库连接方面的修改。我这个是直接解析上传文件，还没有涉及到数据库连接上，整个程序都是utf-8编码，config.encoding也已经设置。
后来参考http://www.cnblogs.com/kting/archive/2011/09/15/2177530.html
后来发现问题出在上传文件的读入上
params[:upload_file].read.encoding
返回的字符串的encoding是 ASCII－8BIT
在这里用params[:upload_file].read.force_encoding(“utf-8”)
之后就正常了。
其间还测试了Iconv.iconv方法，不过不灵，还试了String#toutf8方法，结果字符串变成了空白的，不清楚这个方法是干什么的。</description>
    </item>
    
    <item>
      <title>prawn生成的pdf在chrome中直接显示</title>
      <link>http://superwf.github.io/p272/</link>
      <pubDate>Thu, 19 Apr 2012 08:31:35 +0000</pubDate>
      
      <guid>http://superwf.github.io/p272/</guid>
      <description>今天要调试个pdf生成页面，为了调试方便希望在chrome里直接显示pdf，这样每次刷新就可以看到pdf的变化。
刚开始一点击pdf后浏览器总是自动下载文件。
以为是nginx或者rails里mime的什么设置的问题，后来在controller里的send_data有个参数
disposition: “inline”
之后pdf就能直接显示在chrome里了。</description>
    </item>
    
    <item>
      <title>rubygems-bunlder不用每次都执行bundle exec</title>
      <link>http://superwf.github.io/p269/</link>
      <pubDate>Fri, 13 Apr 2012 02:07:23 +0000</pubDate>
      
      <guid>http://superwf.github.io/p269/</guid>
      <description>找到这么一个好东西
https://github.com/mpapis/rubygems-bundler
安装之后，每次进入程序主目录之后，执行rails、rake等命令
会自动根据当前程序Gemfile里的版本执行对应的程序。
省略了每次必须先敲bundle exec的麻烦。
可喜可贺</description>
    </item>
    
    <item>
      <title>rails aototest not running</title>
      <link>http://superwf.github.io/p267/</link>
      <pubDate>Fri, 13 Apr 2012 02:05:09 +0000</pubDate>
      
      <guid>http://superwf.github.io/p267/</guid>
      <description>在一个新的rails3.2的程序里，打算用郭老师推荐的autotest
可是按教程写的载入之后，运行autotest之后，进程就卡住，根本不往下走，完全不像autotest教程上说的，先自动整体测试一遍。
google之后说是因为rspec升级为rspec2的缘故
在程序主文件夹里放入文件夹 ./autotest/discover.rb
内容为
Autotest.add_discovery { “rspec2” }
然后再执行autotest就能自动执行了。</description>
    </item>
    
    <item>
      <title>nginx passenger rails</title>
      <link>http://superwf.github.io/p219/</link>
      <pubDate>Fri, 10 Feb 2012 02:52:57 +0000</pubDate>
      
      <guid>http://superwf.github.io/p219/</guid>
      <description>前几天去面试，有个题目是关于passenger的
我写没用过，用的是unicorn + nginx
回来之后觉得passenger实在是有必要研究一下
先gem install passenger
然后装nginx的模块
默认编译和我原来的apt装的差了好多参数
选2自己加参数，用nginx -V看看原来的参数，把合适的都加进去，默认路径就/opt/nginx好了
参数如下
–conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-client-body-temp-path=/var/lib/nginx/body –http-fastcgi-temp-path=/var/lib/nginx/fastcgi –http-log-path=/var/log/nginx/access.log –http-proxy-temp-path=/var/lib/nginx/proxy –lock-path=/var/lock/nginx.lock –pid-path=/var/run/nginx.pid –with-http_geoip_module –with-http_gzip_static_module –with-http_realip_module –with-http_stub_status_module –with-http_sub_module –with-mail –with-mail_ssl_module
按编译完的提示在nginx.conf里加上
passenger_root /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.11;
passenger_ruby /usr/bin/ruby1.9.1;
编译好之后把 cp /opt/nginx/sbin/nginx /usr/sbin/nginx里，就直接用了，配置文件什么的都原来的位置
在网站的配置里把我原来的unicorn的配置注释掉
加上 passenger_enabled on;
编译完了之后启动说少了libpcre.so.0
aptitude install libpcre++0
启动之后说
git://github.com/galetahub/simple-captcha.git (at master) is not checked out. Please run `bundle install` (Bundler::GitError)
bundle install 还不管用
搜了搜
用 bundle install –path vendor/
把所有环境都集成到程序里</description>
    </item>
    
    <item>
      <title>rails postgresql</title>
      <link>http://superwf.github.io/p217/</link>
      <pubDate>Wed, 01 Feb 2012 06:54:00 +0000</pubDate>
      
      <guid>http://superwf.github.io/p217/</guid>
      <description>往heroku上推项目，需要支持postgresql
装完之后需要gem install pg
需要libpq-dev的支持</description>
    </item>
    
    <item>
      <title>rails3 ssl https</title>
      <link>http://superwf.github.io/p209/</link>
      <pubDate>Mon, 30 Jan 2012 08:39:17 +0000</pubDate>
      
      <guid>http://superwf.github.io/p209/</guid>
      <description>给项目的登录页面做个https认证，登录后还跳转回http的页面。
先让nginx支持ssl
在网站的配置文件中的server {…} 之前加入
map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}
server {} 内加入
fastcgi_param HTTPS $fastcgi_https;
参考http://www.quany.info/web-design/nginx-400-bad-request-the-plain-http-request-was-sent-to-https-port.html
其他ssl 的配置参考
http://www.linuxidc.com/Linux/2011-09/44187.htm
后来出现了400错误
The page isn’t redirecting properly
试了几回，把 server {} 里的
ssl on;
去掉就好了
只要同时 listen 80;
listen 443; 就行了
然后在程序里的验证身份中
redirect_to url_for(…., :protocol =&amp;gt; ‘https’)
这样写，验证完的跳回80端口 :protocol =&amp;gt; ‘http’
看rails的配置里，需要在confit/application.rb中加入
config.force_ssl = true
我加了之后出现页面循环重定向错误，后来把这个去掉了也没什么问题，觉得不用加这个。</description>
    </item>
    
    <item>
      <title>rails3 update_attributes时不能更新date类型</title>
      <link>http://superwf.github.io/p190/</link>
      <pubDate>Thu, 05 Jan 2012 07:30:11 +0000</pubDate>
      
      <guid>http://superwf.github.io/p190/</guid>
      <description>有个模型Primer的属性是over_date 类型是date
从 nil 更新为 ‘2011-05-06’ 可以
从有 到 无，就不能了
update_attribute update_attributes save
加上叹号，都返回true
但是就是不更新为 NULL
发现 datetime 类型的也有同样的问题
但是在 rails c
命令行下更新就没问题，十分头疼！
最后没辙只好用 update_all 来更新，就是没法调用 before_update 的方法
找出原因，是自己扩展的一个 NillClass的 method_missing方法影响了这个操作
去掉了这个方法就好了。唉，自己作的。</description>
    </item>
    
    <item>
      <title>action_mailer的 view里不能调用helper里的方法</title>
      <link>http://superwf.github.io/p187/</link>
      <pubDate>Wed, 28 Dec 2011 06:27:05 +0000</pubDate>
      
      <guid>http://superwf.github.io/p187/</guid>
      <description>action_mailer的 view里不能调用自定义helper里的方法
但是原生的方法就可以，比如link_to
其他后来定义的方法，比如ApplicationHelper里定义的就会说找不到方法
是用delayedJobs发送的邮件，不知道有没有什么联系</description>
    </item>
    
    <item>
      <title>ruby合并pdf</title>
      <link>http://superwf.github.io/p175/</link>
      <pubDate>Tue, 20 Sep 2011 01:28:06 +0000</pubDate>
      
      <guid>http://superwf.github.io/p175/</guid>
      <description>项目里有个功能需要动态合并很多静态的pdf文件为一个大的pdf文件
没找到好的ruby内置的功能，找了个系统工具pdftk，算是还挺简单的。
http://stackoverflow.com/questions/85459/is-it-possible-to-combine-a-series-of-pdfs-into-one-using-ruby</description>
    </item>
    
    <item>
      <title>ROR中我无法解决的问题</title>
      <link>http://superwf.github.io/p171/</link>
      <pubDate>Wed, 14 Sep 2011 03:41:12 +0000</pubDate>
      
      <guid>http://superwf.github.io/p171/</guid>
      <description>目前已经有两个rails3的系统部署下去使用了，遇到了如下一些问题，至今无法解决。
一个是observer问题
这个observer是记录很多表数据的创建用户用的
class RecordUserObserver &amp;lt; ActiveRecord::Observer include UserSessionsHelper observe Client, ClientEmail, Company, PrintLabel, ReSynthesis, Synthesis, Aminolysis, PageElectrophoresis, Desalt, Drain, Checkout, CheckoutOrder, CheckoutSign, Invoice, InvoiceSign, Cash, BadDebt, User, Role, Price, DeletionLogger, CheckoutPrimer, Order # 记录当前用户 def before_create(record) record.user_id = current_user.id end end 其中用到的 UserSessionsHelper如下 module UserSessionsHelper private # 当前用户的session def current_user_session return @current_user_session if defined?(@current_user_session) @current_user_session = UserSession.find end # 当前登录用户 def current_user return @current_user if defined?(@current_user) @current_user = current_user_session &amp;amp;&amp;amp; current_user_session.</description>
    </item>
    
    <item>
      <title>rails3 sso单点登录</title>
      <link>http://superwf.github.io/p169/</link>
      <pubDate>Fri, 02 Sep 2011 02:02:25 +0000</pubDate>
      
      <guid>http://superwf.github.io/p169/</guid>
      <description>rails3 的单点登录
网上搜说要用什么什么插件，多次实验后发现不用
参考了这个
http://logicsoul.com/2010/rails-3-enabling-cross-sub-domain-sso/
在config/initializers/session_store.rb里
修改
MyApp::Application.config.session_store :active_record, :key =&amp;gt; ‘_sso_session’, :domain =&amp;gt; ‘.superwf.com’
在多个网站中，把:key和:domain 改成一致的，就可以了，session跨数据库共享参见另一篇</description>
    </item>
    
    <item>
      <title>meta结尾的模型名称引起的路由错误</title>
      <link>http://superwf.github.io/p162/</link>
      <pubDate>Tue, 30 Aug 2011 01:58:54 +0000</pubDate>
      
      <guid>http://superwf.github.io/p162/</guid>
      <description>用了个模型叫plasmid_meta，在routes.rb里加了resources :plasmid_metas
结果在form_for 里说找不到路径 plasmid_meta_index_path
估计大概不是meta是个关键字，就是meta结尾的名词复数形式不太一样，后来也没查出来，把模型名改了，以后不用meta结尾的名字了…</description>
    </item>
    
    <item>
      <title>selenium firefox6</title>
      <link>http://superwf.github.io/p159/</link>
      <pubDate>Mon, 29 Aug 2011 02:50:19 +0000</pubDate>
      
      <guid>http://superwf.github.io/p159/</guid>
      <description>升级了ff6，之后跑selenium的测试不动了，报超时错误。
上网搜说是升级selenium-webdriver 到最新的就行了。弄了半天，升级了好几个相关的玩意，才总算又跑起来了，省了给ff降级。</description>
    </item>
    
    <item>
      <title>simple_captcha在production模式不显示</title>
      <link>http://superwf.github.io/p155/</link>
      <pubDate>Thu, 25 Aug 2011 07:13:49 +0000</pubDate>
      
      <guid>http://superwf.github.io/p155/</guid>
      <description>http://stackoverflow.com/questions/5888681/in-my-rails-3-app-simple-captcha-doesnt-display-image-on-production-mode
照做，解决</description>
    </item>
    
    <item>
      <title>rails 不同app间共享session</title>
      <link>http://superwf.github.io/p153/</link>
      <pubDate>Thu, 25 Aug 2011 05:23:49 +0000</pubDate>
      
      <guid>http://superwf.github.io/p153/</guid>
      <description>http://stackoverflow.com/questions/4854577/using-a-sessions-table-from-another-db-in-rails
http://stackoverflow.com/questions/377137/rails-multiple-top-level-domains-and-a-single-session-cookie
参考，完毕</description>
    </item>
    
    <item>
      <title>IE无法登录rails程序</title>
      <link>http://superwf.github.io/p149/</link>
      <pubDate>Fri, 19 Aug 2011 04:18:29 +0000</pubDate>
      
      <guid>http://superwf.github.io/p149/</guid>
      <description>新用的一个内部域名为primer_synthesis.dna.com
页面提示不见容ie6的部分样式，但用户反应用ie8也上不去。我找了个机器用ie6 9 也都上不去。
还以为是authlogic的问题。在我的开发机器上测试就没问题，但是服务器上的就是上不去，明明都是一样的代码。
搜到这个后来
http://www.letrails.cn/archives/ie7-bug-make-rails-session-cant-be-saved/
把域名改了，去了下划线，就OK了</description>
    </item>
    
    <item>
      <title>compass添加52framework</title>
      <link>http://superwf.github.io/p146/</link>
      <pubDate>Fri, 12 Aug 2011 05:23:01 +0000</pubDate>
      
      <guid>http://superwf.github.io/p146/</guid>
      <description>之后，css文件报错说找不到框架
需要在
为
做一个连接</description>
    </item>
    
    <item>
      <title>rails will_paginate ajax</title>
      <link>http://superwf.github.io/p142/</link>
      <pubDate>Tue, 26 Jul 2011 07:52:53 +0000</pubDate>
      
      <guid>http://superwf.github.io/p142/</guid>
      <description>终于到了一个不得不用ajax翻页的应用。搜了搜will_paginate本来的doc没有这个现成的设置，github上倒是有几个应用，看了看都觉得要改动的地方比较多，不舒服。
后来看了一个例子，我用的haml
加上这个js代码确实是产生ajax请求了。
不过请求的页面返回的是html，不知道调用什么才能把新得到的html替换原html
原来问题出在响应的头信息的Content-Type上
又写了个对应的company.js.erb
在里面
带ajax的will_paginate应用OK
在controller 中
format.html 会自动调用 html.haml
format.js 自动调用 js.erb</description>
    </item>
    
    <item>
      <title>rails uninitialized constant Rake::DSL</title>
      <link>http://superwf.github.io/p139/</link>
      <pubDate>Tue, 19 Jul 2011 07:00:09 +0000</pubDate>
      
      <guid>http://superwf.github.io/p139/</guid>
      <description>机器换硬盘，配置新环境之后执行rake报错
该装的都装了。后来又重新gem install rake了两次，才好了，这个问题有点莫名其妙～～～</description>
    </item>
    
    <item>
      <title>rails pdf prawn</title>
      <link>http://superwf.github.io/p137/</link>
      <pubDate>Tue, 19 Jul 2011 06:57:08 +0000</pubDate>
      
      <guid>http://superwf.github.io/p137/</guid>
      <description>最近的项目里有个要打印标签的功能。
本想用mini_magick在图片里写字。因为图片非常小，里面的字体几乎就没法看，没办法需要矢量图的东西。要是ruby没有支持矢量图操作的东西就完蛋了。结果发现pdf算是一种矢量图。后来用pawn生成一个小尺寸的pdf解决了打印问题</description>
    </item>
    
    <item>
      <title>rails3接收email</title>
      <link>http://superwf.github.io/p127/</link>
      <pubDate>Thu, 30 Jun 2011 07:41:16 +0000</pubDate>
      
      <guid>http://superwf.github.io/p127/</guid>
      <description>http://cbpowell.wordpress.com/2011/01/17/saving-attachments-with-ruby-1-9-2-rails-3-and-the-mail-gem/
rails发送邮件，按教程做都很容易，收邮件的事就一笔带过了，官方有个办法，不过还得把你的rails程序部署在你的mail server上，不实用。
参考以上连接的方法实现接收邮件
  </description>
    </item>
    
    <item>
      <title>attachment_fu的图片裁减生成缩略图</title>
      <link>http://superwf.github.io/p73/</link>
      <pubDate>Wed, 25 May 2011 13:12:24 +0000</pubDate>
      
      <guid>http://superwf.github.io/p73/</guid>
      <description>attachment_fu默认的缩略图是直接生成，没有裁减的，对于不是正方形的图生成的缩略图不太好看。
后来参考了张磊的一个帖子
http://www.blogkid.net/archives/tag/%E5%9B%BE%E7%89%87
改用mini_magick
在model里添加了方法
但是 :resize_to =&amp;gt; ‘800&amp;gt;’这个总是捣乱，不光把缩略图裁减了，还把原图也跟着裁减
后来看了好长时间attachement_fu的源文件，在attachment_fu.rb里的
改一下，只进行一次resize_to就好了。</description>
    </item>
    
    <item>
      <title>rails3版本You have already activated依赖问题</title>
      <link>http://superwf.github.io/p43/</link>
      <pubDate>Thu, 12 May 2011 01:48:10 +0000</pubDate>
      
      <guid>http://superwf.github.io/p43/</guid>
      <description>gem update之后，好多东西升级了之后原来的项目不能启动了，报错信息为
You have already activated rack 1.3.0.beta, but your Gemfile requires rack 1.2.2
于是在Gemfile里指定gem ‘rack’, ‘1.2.2’
这样之后，rails server倒是没问题
但是
还是报错，看提示有个让用bundle exec的说法
一试还真成
启动OK</description>
    </item>
    
    <item>
      <title>rails3.1 ExecJS::RuntimeError</title>
      <link>http://superwf.github.io/p39/</link>
      <pubDate>Wed, 11 May 2011 06:45:51 +0000</pubDate>
      
      <guid>http://superwf.github.io/p39/</guid>
      <description>rails3.1默认jquery 虽然还是beta版但也欣然的用上了
不过一rails g controller home index
application.js就报错，查了半天，是execjs没有runtime运行环境，还要v8什么的，没听说过了。gem 也搜不到v8这么个东西
gem install therubyracer报错，说编译错误什么的，原来也要依赖的东西
https://github.com/cowboyd/therubyracer
按照上面说的做
好吧我不愧是编译型语言的门外汉。原来少了g++这个东西
一直以为gcc就全搞定了呢
aptitude g++之后，在执行以上命令就OK了</description>
    </item>
    
    <item>
      <title>添加商品model时 valid? 错误</title>
      <link>http://superwf.github.io/p31/</link>
      <pubDate>Wed, 27 Apr 2011 07:02:59 +0000</pubDate>
      
      <guid>http://superwf.github.io/p31/</guid>
      <description>添加product 时设置了一个字段为valid，没注意和active_record本身的方法冲突了，无法使用，同理freeze frozen因该也不能用，只好用show代替。</description>
    </item>
    
    <item>
      <title>active_record 的 changed</title>
      <link>http://superwf.github.io/p20/</link>
      <pubDate>Tue, 26 Apr 2011 07:13:32 +0000</pubDate>
      
      <guid>http://superwf.github.io/p20/</guid>
      <description>本来想这样
Client.all.each do |c|
c.name.strip!
c.save
end
但是不起作用
试了一下发现
c.name.strip!之后
c.changed? 还是false
必须用 = 赋值操作，才能save成
必须 c.name = c.name.strip 才可以</description>
    </item>
    
    <item>
      <title>2rails3 project init</title>
      <link>http://superwf.github.io/p10/</link>
      <pubDate>Mon, 11 Apr 2011 07:12:26 +0000</pubDate>
      
      <guid>http://superwf.github.io/p10/</guid>
      <description>安装msyql2 需要系统库libmysqlclient-dev 和 ruby1.9.1-dev libmysql-ruby1.9.1
nokogiri需要 libxml2-dev libxslt1-dev
readline需要 libreadline-dev
安装rmagick
需要 imagemagick libmagick9-dev
在wheezy版本中的3.2.0的linux内核系统下，需要libmagickwand-dev，而没有libmagick9-dev这个包了。
openssl 问题需要 libssl-dev
后来改用rvm安装ruby，每次换系统的时候都马上把ruby先装上，然后等运行rails的时候报错还的重新编译ruby
总结了一下，rvm装ruby之前，需要先apt安装好 libmysqlclient-dev libssl-dev libmagickwand-dev
curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable
后来系统升级了,curl会报错
Could not download ‘https://github.com/wayneeseguin/rvm/tarball/master’.
curl returned status ‘141’.
是因为curl的安全设置不允许默认下载https的东西
需要 echo insecure &amp;raquo; ~/.curlrc</description>
    </item>
    
    <item>
      <title>rails using openssl</title>
      <link>http://superwf.github.io/p8/</link>
      <pubDate>Thu, 07 Apr 2011 08:14:32 +0000</pubDate>
      
      <guid>http://superwf.github.io/p8/</guid>
      <description>  </description>
    </item>
    
    <item>
      <title>之前的以项目运行不起来</title>
      <link>http://superwf.github.io/p3/</link>
      <pubDate>Wed, 06 Apr 2011 07:27:58 +0000</pubDate>
      
      <guid>http://superwf.github.io/p3/</guid>
      <description>unicorn启动提示rack版本不对，找了半天发现是之前把gem都freeze在vender/cache里了
重新bundle update之后更新所有的gem依赖包搞定</description>
    </item>
    
    <item>
      <title>ruby脚本无法在crontab里运行的问题</title>
      <link>http://superwf.github.io/p4/</link>
      <pubDate>Sat, 02 Apr 2011 01:49:12 +0000</pubDate>
      
      <guid>http://superwf.github.io/p4/</guid>
      <description>昨天搞了大半天，弄了个rails3的non-browser程序，就当脚本运行
写了个bash脚本运行这个rb程序，按说把ruby xxx.rb直接放到cron里运行也行，不过由于运行时间间隔较短，可能出现重复运行的情况，放到bash脚本里，每次运行时先查一下进程里有没有运行这个脚本，如果没有则运行之。本来这个检测都交给ruby运行也可以，不过如果出现什么timeout的错误退出了就必须人工启动了。
写好之后，直接运行这个xxx.sh脚本运行这个xxx.rb程序，没有任何问题，但是放到crontab里就不行，来回调试，后来回家半夜了发现在cron里运行完xxx.rb之后的$?为1，然后仔细看了看我的xxx.rb
原来的写法是
终于想明白了原来在cron中运行的程序都必须取得绝对路径
照着config/application.rb里的写法，改成
正常运行了！</description>
    </item>
    
  </channel>
</rss>