<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Enjoy Rails</title>
	<atom:link href="http://blog.enjoyrails.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.enjoyrails.com</link>
	<description></description>
	<pubDate>Thu, 21 Jan 2010 14:39:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Passenger新版本request_uri header自动转码的问题</title>
		<link>http://blog.enjoyrails.com/2010/01/21/passenger-request_uri-header-auto-decode/</link>
		<comments>http://blog.enjoyrails.com/2010/01/21/passenger-request_uri-header-auto-decode/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 14:39:03 +0000</pubDate>
		<dc:creator>HoLin</dc:creator>
		
		<category><![CDATA[部署与优化]]></category>

		<category><![CDATA[nginx]]></category>

		<category><![CDATA[passenger]]></category>

		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/?p=220</guid>
		<description><![CDATA[Nginx access.log :
127.0.0.1 - - [21/Jan/2010:21:13:58 +0800] &#8220;GET /notes/Books+%2B+Online+Video+%3D+Vooks%3A+Watchable%2C+Readable%2C+%26+Very+Cool HTTP/1.1&#8243; 304 0 &#8220;-&#8221; &#8220;Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7&#8243;
到Rails之后log/production.log：
Completed in 123ms (View: 8, DB: 62) &#124; 200 OK [http://i/notes/Books+++Online+Video+=+Vooks:+Watchable,+Readable,+&#038;+Very+Cool]
url被自动decode了，在我们的项目中并不想要这样的结果。
网上查了很多资料，Apache版本有类似 AllowEncodedSlashes 的指令。Nginx暂时没有。
对比了passenger-2.2.4和passenger-2.2.9，在文件ext/nginx/Configuration.c中有一行代码和这个相关。
2.2.9:
DEFINE_VAR_TO_PASS(&#8221;REQUEST_URI&#8221;,     &#8220;$uri$is_args$args&#8221;);
2.2.4
DEFINE_VAR_TO_PASS(&#8221;REQUEST_URI&#8221;,     &#8220;$request_uri&#8221;);
用2.2.4的替换2.2.9的，重新编译就可以了。
收藏、分享这篇文章!


No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Nginx access.log :</p>
<blockquote><p>127.0.0.1 - - [21/Jan/2010:21:13:58 +0800] &#8220;GET /notes/Books+%2B+Online+Video+%3D+Vooks%3A+Watchable%2C+Readable%2C+%26+Very+Cool HTTP/1.1&#8243; 304 0 &#8220;-&#8221; &#8220;Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7&#8243;</p></blockquote>
<p>到Rails之后log/production.log：</p>
<blockquote><p>Completed in 123ms (View: 8, DB: 62) | 200 OK [http://i/notes/Books+++Online+Video+=+Vooks:+Watchable,+Readable,+&#038;+Very+Cool]</p></blockquote>
<p>url被自动decode了，在我们的项目中并不想要这样的结果。</p>
<p>网上查了很多资料，Apache版本有类似 AllowEncodedSlashes 的指令。Nginx暂时没有。</p>
<p>对比了passenger-2.2.4和passenger-2.2.9，在文件ext/nginx/Configuration.c中有一行代码和这个相关。<br />
2.2.9:</p>
<p>DEFINE_VAR_TO_PASS(&#8221;REQUEST_URI&#8221;,     &#8220;$uri$is_args$args&#8221;);</p>
<p>2.2.4</p>
<p>DEFINE_VAR_TO_PASS(&#8221;REQUEST_URI&#8221;,     &#8220;$request_uri&#8221;);</p>
<p>用2.2.4的替换2.2.9的，重新编译就可以了。</p>
<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=220&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_220" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2010/01/21/passenger-request_uri-header-auto-decode/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Nagios中用飞信发送报警信息</title>
		<link>http://blog.enjoyrails.com/2009/12/04/nagios%e4%b8%ad%e7%94%a8%e9%a3%9e%e4%bf%a1%e5%8f%91%e9%80%81%e6%8a%a5%e8%ad%a6%e4%bf%a1%e6%81%af/</link>
		<comments>http://blog.enjoyrails.com/2009/12/04/nagios%e4%b8%ad%e7%94%a8%e9%a3%9e%e4%bf%a1%e5%8f%91%e9%80%81%e6%8a%a5%e8%ad%a6%e4%bf%a1%e6%81%af/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 03:32:31 +0000</pubDate>
		<dc:creator>devon</dc:creator>
		
		<category><![CDATA[部署与优化]]></category>

		<category><![CDATA[nagios]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/?p=216</guid>
		<description><![CDATA[近期由于飞信的API变更，原先的Linux版本fetion程序不能再用来发送信息了。而由 flyerhzm 开发的rfetion更新较快，可用来配合Nagios的报警信息发送。
rfetion是基于ruby的一个飞信客户端工具，有命令行的发送模式。使用前，需事先安装好 ruby，及rubygem，相关安装过程在网上有很多。
安装好ruby及rubygem后，可通过如下两行命令来安装rfetion：

1
2
gem sources -a http://gemcutter.org
sudo gem install rfetion

在nagios中增加用飞信发送报警信息的命令。需要注意的是rfetion可执行文件的路径/usr/local/ruby/bin/rfetion在不同平台可能会稍有区别，请根据自己的实际情况处理。同时，命令中的手机号与密码需要修改为对应的用于发送通知的飞信手机号码与密码。

1
2
3
4
5
6
7
8
9
define command &#123;
  	command_name     host-notify-by-sms
  	command_line     /usr/local/ruby/bin/rfetion --silence -m 18888888888 -p my_password -f $CONTACTPAGER$ -c &#34;Host $HOSTSTATE$ alert for $HOSTNAME$! on $SHORTDATETIME$&#34;
&#125;
&#160;
define command &#123;
  	command_name     service-notify-by-sms
  	command_line    [...]


Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/01/25/nginx-boot-script/' rel='bookmark' title='Permanent Link: Nginx boot script'>Nginx boot script</a> <small>目的：让nginx随服务器启动 操作系统： Linux localhost.localdomain 2.6.9-42.ELsmp #1 SMP Wed Jul 12...</small></li><li><a href='http://blog.enjoyrails.com/2009/05/22/195/' rel='bookmark' title='Permanent Link: Nginx + Passenger 开发Rails应用'>Nginx + Passenger 开发Rails应用</a> <small>在Rails开发过程中，如果同时开发多个项目，需要经常切换，使用 script/server 去启动应用会比较麻烦，而采用nginx(或apache) + passenger可以节约时间，提高效率。 １、安装passenger 下载Passenger，目前最新的版本为2.2.2，并解压到passenger的安装目录： tar xzvf passenger-2.2.2.tar.gz...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>近期由于飞信的API变更，原先的Linux版本fetion程序不能再用来发送信息了。而由 <a href="http://www.huangzhimin.com/">flyerhzm</a> 开发的rfetion更新较快，可用来配合Nagios的报警信息发送。</p>
<p>rfetion是基于ruby的一个飞信客户端工具，有命令行的发送模式。使用前，需事先安装好 ruby，及rubygem，相关安装过程在网上有很多。</p>
<p>安装好ruby及rubygem后，可通过如下两行命令来安装rfetion：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">gem sources <span style="color: #660033;">-a</span> http:<span style="color: #000000; font-weight: bold;">//</span>gemcutter.org
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rfetion</pre></td></tr></table></div>

<p>在nagios中增加用飞信发送报警信息的命令。需要注意的是rfetion可执行文件的路径/usr/local/ruby/bin/rfetion在不同平台可能会稍有区别，请根据自己的实际情况处理。同时，命令中的手机号与密码需要修改为对应的用于发送通知的飞信手机号码与密码。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">define <span style="color: #7a0874; font-weight: bold;">command</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  	command_name     host-notify-by-sms
  	command_line     <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rfetion <span style="color: #660033;">--silence</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">18888888888</span> <span style="color: #660033;">-p</span> my_password <span style="color: #660033;">-f</span> <span style="color: #007800;">$CONTACTPAGER</span>$ <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;Host $HOSTSTATE$ alert for $HOSTNAME$! on $SHORTDATETIME$&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
define <span style="color: #7a0874; font-weight: bold;">command</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  	command_name     service-notify-by-sms
  	command_line     <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rfetion <span style="color: #660033;">--silence</span> <span style="color: #660033;">-m</span> <span style="color: #000000;">18888888888</span> <span style="color: #660033;">-p</span> my_password <span style="color: #660033;">-f</span> <span style="color: #007800;">$CONTACTPAGER</span>$ <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;'$HOSTADDRESS$' $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $SHORTDATETIME$&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>在对应的的contact定义里，定义报警信息发送使用service-notify-by-sms、host-notify-by-sms，并在pager一行中写入待通知的手机号码。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">define contact<span style="color: #7a0874; font-weight: bold;">&#123;</span>
        contact_name    henry
        use             generic-contact
        <span style="color: #7a0874; font-weight: bold;">alias</span>           heyry
        service_notification_commands   service-notify-by-sms
        host_notification_commands      host-notify-by-sms
&nbsp;
        email           demo<span style="color: #000000; font-weight: bold;">@</span>demo.gmail
        pager           <span style="color: #000000;">18666666666</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>重新加载nagios后，报警信息即可通过飞信来发送。</p>
<p>rfetion还有其它更强大的功能，具体信息可通过 <a href="http://github.com/flyerhzm/rfetion"> rfetion api and source code </a></p>
<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=216&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_216" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/01/25/nginx-boot-script/' rel='bookmark' title='Permanent Link: Nginx boot script'>Nginx boot script</a> <small>目的：让nginx随服务器启动 操作系统： Linux localhost.localdomain 2.6.9-42.ELsmp #1 SMP Wed Jul 12...</small></li><li><a href='http://blog.enjoyrails.com/2009/05/22/195/' rel='bookmark' title='Permanent Link: Nginx + Passenger 开发Rails应用'>Nginx + Passenger 开发Rails应用</a> <small>在Rails开发过程中，如果同时开发多个项目，需要经常切换，使用 script/server 去启动应用会比较麻烦，而采用nginx(或apache) + passenger可以节约时间，提高效率。 １、安装passenger 下载Passenger，目前最新的版本为2.2.2，并解压到passenger的安装目录： tar xzvf passenger-2.2.2.tar.gz...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2009/12/04/nagios%e4%b8%ad%e7%94%a8%e9%a3%9e%e4%bf%a1%e5%8f%91%e9%80%81%e6%8a%a5%e8%ad%a6%e4%bf%a1%e6%81%af/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Jquery 表格工具 &#8212; 2dc_jqgrid&#8212;&#8212;&#8212;&#8212;&#8211;</title>
		<link>http://blog.enjoyrails.com/2009/05/24/jquery-%e8%a1%a8%e6%a0%bc%e5%b7%a5%e5%85%b7-2dc_jqgrid/</link>
		<comments>http://blog.enjoyrails.com/2009/05/24/jquery-%e8%a1%a8%e6%a0%bc%e5%b7%a5%e5%85%b7-2dc_jqgrid/#comments</comments>
		<pubDate>Sun, 24 May 2009 01:02:28 +0000</pubDate>
		<dc:creator>wosmvp</dc:creator>
		
		<category><![CDATA[Plugin]]></category>

		<category><![CDATA[Rails应用]]></category>

		<category><![CDATA[web前端技术]]></category>

		<category><![CDATA[敏捷开发]]></category>

		<category><![CDATA[测试方法]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/?p=201</guid>
		<description><![CDATA[它整合了 InPlaceEdit，分页，搜索，添加,删除等功能,甚至还可以处理附属关系的表格
功能不可谓不强大，但代码却是来的简单的很！
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
- Ajax enabled
- Sorting
- Pagination
- Search
- CRUD operations (add, edit, delete)
- Multi-selection (checkboxes)
- Master-details
- Themes
- And more ...
--------------
The jQuery grid plugin is an amazing Javascript project providing multi-functions Ajax datagrids for your web applications.简而言之，居家旅行杀人放火逃命跳墙之必备良品！
在官方文档面前，任何其它文档都是失色的 http://www.2dconcept.com/jquery-grid-rails-plugin
在这里就不无聊的敷述一下过程了
简单的谈几其它个问题：
1，它的例子代码太“重量级”：
针对它第一个例子方法的优化：
原方法：

users = User.find&#40;:all&#41; do
    if params&#91;:_search&#93; == &#34;true&#34;
      pseudo    [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>它整合了 <strong>InPlaceEdit</strong>，<strong>分页</strong>，<strong>搜索，添加,删除</strong>等功能,甚至还可以处理<strong>附属关系</strong>的表格</p>
<p>功能不可谓不强大，但代码却是来的简单的很！</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<pre>- Ajax enabled
- Sorting
- Pagination
- Search
- CRUD operations (add, edit, delete)
- Multi-selection (checkboxes)
- Master-details
- Themes
- And more ...
--------------</pre>
<p>The <a href="http://www.trirand.com/jqgrid35/jqgrid.html" target="_blank">jQuery grid plugin</a> is an <strong>amazing </strong>Javascript project providing multi-functions Ajax datagrids for your web applications.简而言之，<strong>居家旅行杀人放火逃命跳墙之必备良品！</strong></p>
<p>在官方文档面前，任何其它文档都是失色的 http://www.2dconcept.com/jquery-grid-rails-plugin</p>
<p>在这里就不无聊的敷述一下过程了</p>
<p>简单的谈几其它个问题：</p>
<p>1，它的例子代码太“重量级”：</p>
<p>针对它第一个例子方法的优化：</p>
<p>原方法：</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">users = User.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:_search</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">&quot;true&quot;</span>
      pseudo    =~ <span style="color:#996600;">&quot;%#{params[:pseudo]}%&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:pseudo</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">present</span>?
      firstname =~ <span style="color:#996600;">&quot;%#{params[:firstname]}%&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:firstname</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">present</span>?
      lastname  =~ <span style="color:#996600;">&quot;%#{params[:lastname]}%&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:lastname</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">present</span>?
      email     =~ <span style="color:#996600;">&quot;%#{params[:email]}%&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:email</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">present</span>?
      role      =~ <span style="color:#996600;">&quot;%#{params[:role]}%&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:role</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">present</span>?
    <span style="color:#9966CC; font-weight:bold;">end</span>
    paginate <span style="color:#ff3333; font-weight:bold;">:page</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:page</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:per_page</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:rows</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    order_by <span style="color:#996600;">&quot;#{params[:sidx]} #{params[:sord]}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>修改后：</p>

<div class="wp_syntax"><div class="code"><pre class="ruby ruby" style="font-family:monospace;">users = User.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |x|
    <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:_search</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">&quot;true&quot;</span>
       <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:pseudo</span>,:firstname,:lastname,:email,:role<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">map</span> <span style="color:#9966CC; font-weight:bold;">do</span> |m|
           x.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>m<span style="color:#006600; font-weight:bold;">&#41;</span> =~ <span style="color:#996600;">&quot;%#{params[m]}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> params<span style="color:#006600; font-weight:bold;">&#91;</span>m<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">presend</span>?
       <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
    paginate <span style="color:#ff3333; font-weight:bold;">:page</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:page</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:per_page</span> =<span style="color:#006600; font-weight:bold;">&amp;</span>gt; params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:rows</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    order_by <span style="color:#996600;">&quot;#{params[:sidx]} #{params[:sord]}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>2, 第二个问题就是如果你上面的order_by排序排字字段使用了SQL的关键字会出现问题的！<br />
上解决方案：<br />
order_by &#8220;`#{params[:sidx]}` #{params[:sord]}&#8221; if<br />
!params[:sidx].blank?</p>
<p>3,上我自己做的中文翻译 <img src='http://blog.enjoyrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  <a href="http://www.zhangjinzhu.com/grid.locale-cn.js" target="_blank">点击下载</a><br />
你需要修改javascripts/jqgrid/jquery.jqGrid.js第10行附近来使用此中文翻译</p>
<p>并且我还修改了源码 vendor/plugins/2dc_jqgrid/lib/2dc_jqgrid.rb第233行，将其中的caption “Search” 修改为“搜索”<br />
（PS：我知道偷偷修改源码，这是很不好的的做法，那怕是字符串的修改，但实在没有找到更优雅一点的办法，有时间再深入它的源码看看吧 <img src='http://blog.enjoyrails.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=201&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_201" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2009/05/24/jquery-%e8%a1%a8%e6%a0%bc%e5%b7%a5%e5%85%b7-2dc_jqgrid/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Nginx + Passenger 开发Rails应用</title>
		<link>http://blog.enjoyrails.com/2009/05/22/195/</link>
		<comments>http://blog.enjoyrails.com/2009/05/22/195/#comments</comments>
		<pubDate>Fri, 22 May 2009 01:20:01 +0000</pubDate>
		<dc:creator>devon</dc:creator>
		
		<category><![CDATA[Rails应用]]></category>

		<category><![CDATA[rails development]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/?p=195</guid>
		<description><![CDATA[在Rails开发过程中，如果同时开发多个项目，需要经常切换，使用 script/server 去启动应用会比较麻烦，而采用nginx(或apache) + passenger可以节约时间，提高效率。
１、安装passenger
下载Passenger，目前最新的版本为2.2.2，并解压到passenger的安装目录：

1
2
tar xzvf passenger-2.2.2.tar.gz /usr/local/passenger
./passenger-2.2.2/bin/passenger-install-nginx-module

按提示操作安装nginx与passenger。
也可以通过gem方式来安装：

1
2
gem install passenger
passenger-install-nginx-module

２、配置nginx
/usr/local/nginx/conf/nginx.conf，在http段加上：

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
http&#123;
	...
	passenger_root /usr/local/passenger;
	passenger_ruby /usr/local/bin/ruby;
&#160;
	server &#123;
		listen 80;
		server_name app1;
		root /Users/jack/app1/public;
		passenger_enabled on;
		rails_env development;
   	&#125;
&#160;
	server &#123;
		listen 80;
		server_name app2;
		root /Users/jack/app2/public;
		passenger_enabled on;
		rails_env development;
   	&#125;
	...
&#125;

3、启动与停止nginx的命令
假设nginx安装在/usr/local/nginx目录里。将如下命令加到~/.bashrc(linux)、 ~/.bash_profile(Mac)

1
2
3
alias sn='sudo /usr/local/nginx/sbin/nginx' 
alias kn='sudo kill `cat /usr/local/nginx/logs/nginx.pid `' 
alias rn='kn; sn'

４、增加应用的host到/etc/hosts，如：

1
2
127.0.0.1 app1
127.0.0.1 app2

这样，在开发时，可以在浏览器中，直接用app1, app2去访问各个应用，再也不用去script/server之类的了。
收藏、分享这篇文章!


Related posts:Nginx boot script 目的：让nginx随服务器启动 操作系统： Linux localhost.localdomain 2.6.9-42.ELsmp #1 SMP [...]


Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/01/25/nginx-boot-script/' rel='bookmark' title='Permanent Link: Nginx boot script'>Nginx boot script</a> <small>目的：让nginx随服务器启动 操作系统： Linux localhost.localdomain 2.6.9-42.ELsmp #1 SMP Wed Jul 12...</small></li><li><a href='http://blog.enjoyrails.com/2008/01/08/deploy-rails-with-nginx-and-mongrel/' rel='bookmark' title='Permanent Link: 使用Nginx和Mongrel Cluster部署Rails应用'>使用Nginx和Mongrel Cluster部署Rails应用</a> <small>本文介绍在Linux上以Nginx为前端、Mongrel Cluster为后端部署Rails应用的方法及步骤。 平台：Ubuntu 7.10 (Gutsy Gibbon) Nginx简介Nginx是由俄罗斯人Igor Sysoev开发的一款HTTP服务器。它有以下特点： 轻量小巧(相对于Apache等) 快速高效...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>在Rails开发过程中，如果同时开发多个项目，需要经常切换，使用 script/server 去启动应用会比较麻烦，而采用nginx(或apache) + passenger可以节约时间，提高效率。</p>
<p>１、安装passenger<br />
下载<a href="http://www.modrails.com/install.html">Passenger</a>，目前最新的版本为<a href="http://rubyforge.org/frs/download.php/55743/passenger-2.2.2.tar.gz">2.2.2</a>，并解压到passenger的安装目录：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf passenger-2.2.2.tar.gz <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>passenger
.<span style="color: #000000; font-weight: bold;">/</span>passenger-2.2.2<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>passenger-install-nginx-module</pre></td></tr></table></div>

<p>按提示操作安装nginx与passenger。</p>
<p>也可以通过gem方式来安装：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">gem <span style="color: #c20cb9; font-weight: bold;">install</span> passenger
passenger-install-nginx-module</pre></td></tr></table></div>

<p>２、配置nginx<br />
/usr/local/nginx/conf/nginx.conf，在http段加上：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">http<span style="color: #7a0874; font-weight: bold;">&#123;</span>
	...
	passenger_root <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>passenger;
	passenger_ruby <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby;
&nbsp;
	server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		listen <span style="color: #000000;">80</span>;
		server_name app1;
		root <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jack<span style="color: #000000; font-weight: bold;">/</span>app1<span style="color: #000000; font-weight: bold;">/</span>public;
		passenger_enabled on;
		rails_env development;
   	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		listen <span style="color: #000000;">80</span>;
		server_name app2;
		root <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>jack<span style="color: #000000; font-weight: bold;">/</span>app2<span style="color: #000000; font-weight: bold;">/</span>public;
		passenger_enabled on;
		rails_env development;
   	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
	...
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p>3、启动与停止nginx的命令</p>
<p>假设nginx安装在/usr/local/nginx目录里。将如下命令加到~/.bashrc(linux)、 ~/.bash_profile(Mac)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">sn</span>=<span style="color: #ff0000;">'sudo /usr/local/nginx/sbin/nginx'</span> 
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">kn</span>=<span style="color: #ff0000;">'sudo kill `cat /usr/local/nginx/logs/nginx.pid `'</span> 
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">rn</span>=<span style="color: #ff0000;">'kn; sn'</span></pre></td></tr></table></div>

<p>４、增加应用的host到/etc/hosts，如：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">127.0.0.1 app1
127.0.0.1 app2</pre></td></tr></table></div>

<p>这样，在开发时，可以在浏览器中，直接用app1, app2去访问各个应用，再也不用去script/server之类的了。</p>
<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=195&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_195" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/01/25/nginx-boot-script/' rel='bookmark' title='Permanent Link: Nginx boot script'>Nginx boot script</a> <small>目的：让nginx随服务器启动 操作系统： Linux localhost.localdomain 2.6.9-42.ELsmp #1 SMP Wed Jul 12...</small></li><li><a href='http://blog.enjoyrails.com/2008/01/08/deploy-rails-with-nginx-and-mongrel/' rel='bookmark' title='Permanent Link: 使用Nginx和Mongrel Cluster部署Rails应用'>使用Nginx和Mongrel Cluster部署Rails应用</a> <small>本文介绍在Linux上以Nginx为前端、Mongrel Cluster为后端部署Rails应用的方法及步骤。 平台：Ubuntu 7.10 (Gutsy Gibbon) Nginx简介Nginx是由俄罗斯人Igor Sysoev开发的一款HTTP服务器。它有以下特点： 轻量小巧(相对于Apache等) 快速高效...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2009/05/22/195/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Leopard为不同的应用程序保留输入法状态</title>
		<link>http://blog.enjoyrails.com/2009/02/11/leopard%e4%b8%ba%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%bf%9d%e7%95%99%e8%be%93%e5%85%a5%e6%b3%95%e7%8a%b6%e6%80%81/</link>
		<comments>http://blog.enjoyrails.com/2009/02/11/leopard%e4%b8%ba%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%bf%9d%e7%95%99%e8%be%93%e5%85%a5%e6%b3%95%e7%8a%b6%e6%80%81/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 05:45:59 +0000</pubDate>
		<dc:creator>devon</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[mac tips]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/?p=191</guid>
		<description><![CDATA[Ｍac 10.5(Leopard)去掉了为单独窗口设置单独输入法的选项，取而代之的是全局输入法，需要不停的切换切换切换，很不方便。（这个功能在tiger上还可以使用的）
用inputswitcher可以替换的实现这个功能。步骤为：

下载并安装 SIMBL
下载 inputswitcher , 并解压
InputSwitcher.app &#8594; /Applications
InputSwitcherClient.bundle &#8594; /Library/Application Support/SIMBL/Plugins
启动InputSwitcher.app，并重启其它应用程序，就可以为不同的应用程序窗口保留输入法状态了。

参考：http://limechat.net/inputswitcher/
收藏、分享这篇文章!


Related posts:ruby on rails dictionary for macosx 在Dictionary中搜索API。 使用方法: 下载文档 解压至~/Library/Dictionaries/ 或 /Library/Dictionaries/ 打开Dictionary → Preferences, 选中ruby,...
Related posts brought to you by Yet Another Related Posts Plugin.


Related posts:<ol><li><a href='http://blog.enjoyrails.com/2009/02/08/ruby-on-rails-dictionary-for-macosx/' rel='bookmark' title='Permanent Link: ruby on rails dictionary for macosx'>ruby on rails dictionary for macosx</a> <small>在Dictionary中搜索API。 使用方法: 下载文档 解压至~/Library/Dictionaries/ 或 /Library/Dictionaries/ 打开Dictionary → Preferences, 选中ruby,...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Ｍac 10.5(Leopard)去掉了为单独窗口设置单独输入法的选项，取而代之的是全局输入法，需要不停的切换切换切换，很不方便。（这个功能在tiger上还可以使用的）</p>
<p>用inputswitcher可以替换的实现这个功能。步骤为：</p>
<ol>
<li>下载并安装 <a href="http://www.culater.net/dl/files/SIMBL-0.8.2.tbz　"><span class="caps">SIMBL</span></a></li>
<li>下载 <a href="http://limechat.net/inputswitcher/InputSwitcher_1.0.zip">inputswitcher</a> , 并解压</li>
<li>InputSwitcher.app &#8594; /Applications</li>
<li>InputSwitcherClient.bundle &#8594; /Library/Application Support/<span class="caps">SIMBL</span>/Plugins</li>
<li>启动InputSwitcher.app，并重启其它应用程序，就可以为不同的应用程序窗口保留输入法状态了。</li>
</ol>
<p>参考：<a href="http://limechat.net/inputswitcher/">http://limechat.net/inputswitcher/</a></p>
<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=191&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_191" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>Related posts:<ol><li><a href='http://blog.enjoyrails.com/2009/02/08/ruby-on-rails-dictionary-for-macosx/' rel='bookmark' title='Permanent Link: ruby on rails dictionary for macosx'>ruby on rails dictionary for macosx</a> <small>在Dictionary中搜索API。 使用方法: 下载文档 解压至~/Library/Dictionaries/ 或 /Library/Dictionaries/ 打开Dictionary → Preferences, 选中ruby,...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2009/02/11/leopard%e4%b8%ba%e4%b8%8d%e5%90%8c%e7%9a%84%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e4%bf%9d%e7%95%99%e8%be%93%e5%85%a5%e6%b3%95%e7%8a%b6%e6%80%81/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ruby on rails dictionary for macosx</title>
		<link>http://blog.enjoyrails.com/2009/02/08/ruby-on-rails-dictionary-for-macosx/</link>
		<comments>http://blog.enjoyrails.com/2009/02/08/ruby-on-rails-dictionary-for-macosx/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 00:50:25 +0000</pubDate>
		<dc:creator>devon</dc:creator>
		
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/?p=188</guid>
		<description><![CDATA[在Dictionary中搜索API。
使用方法:

下载文档
解压至~/Library/Dictionaries/ 或 /Library/Dictionaries/
打开Dictionary → Preferences, 选中ruby, 并拖至最顶点，这样，就可以spotlight来搜索API了。

收藏、分享这篇文章!


No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p>在Dictionary中搜索API。</p>
<p>使用方法:</p>
<ul>
<li><a href="http://www.priithaamer.com/blog/ruby-on-rails-dictionary-for-macosx">下载文档</a></li>
<li>解压至~/Library/Dictionaries/ 或 /Library/Dictionaries/</li>
<li>打开Dictionary → Preferences, 选中ruby, 并拖至最顶点，这样，就可以spotlight来搜索API了。</li>
</ul>
<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=188&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_188" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2009/02/08/ruby-on-rails-dictionary-for-macosx/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Satellite: a self-syncing distributed wiki</title>
		<link>http://blog.enjoyrails.com/2009/01/22/satellite-a-self-syncing-distributed-wiki/</link>
		<comments>http://blog.enjoyrails.com/2009/01/22/satellite-a-self-syncing-distributed-wiki/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 09:14:27 +0000</pubDate>
		<dc:creator>HoLin</dc:creator>
		
		<category><![CDATA[Ruby应用]]></category>

		<category><![CDATA[个人知识管理]]></category>

		<category><![CDATA[git]]></category>

		<category><![CDATA[pkm]]></category>

		<category><![CDATA[satellite]]></category>

		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/2009/01/22/satellite-a-self-syncing-distributed-wiki/</guid>
		<description><![CDATA[介绍

satellite is a self-syncing distributed wiki with file uploads and all sorts of other useful features like offline editing.

主要的特性有：

textile的wiki语法
支持文件上传
所有文档基于git存储与管理
离线编辑，并可自动同步到服务器
支持代码高亮
全面快捷键支持

经我们测试，用于个人知识管理，非常棒。
安装

安装 Git! (and Ruby)


获取代码，原始代码在&#8221;这里&#8221;:http://github.com/kenpratt/satellite/tree/master ，我们fork出了一个版本(http://github.com/holin/satellite/tree/master)，根据中文环境和自己的实际需求增加了一些功能，具体看 satellit扩展功能。


1
$ git clone git@github.com:holin/satellite.git satellite


安装gems， {color:red}注意 ，rack要求使用0.4版本（其它版本未完整测试，最新的0.9rack不能用）


1
2
3
4
$ sudo gem install rack mongrel metaid erubis RedCloth coderay
 $ cd path/to/satellite
 $ git submodule init
 $ git submodule update


配置应用，下方其他中有公开git repository申请说明


1
cd path/to/satellite


edit conf/production.rb
production.rb example


1
2
3
4
5
6
7
8
9
10
11
12
13
14
# production [...]


Related posts:<ol><li><a href='http://blog.enjoyrails.com/2009/01/07/shoulda-on-rails/' rel='bookmark' title='Permanent Link: shoulda on rails'>shoulda on rails</a> <small>在新项目中配置shoulda rails shoulda_demo -d mysql cd shoulda_demo/ script/plugin install git://github.com/thoughtbot/shoulda.git...</small></li><li><a href='http://blog.enjoyrails.com/2009/12/04/nagios%e4%b8%ad%e7%94%a8%e9%a3%9e%e4%bf%a1%e5%8f%91%e9%80%81%e6%8a%a5%e8%ad%a6%e4%bf%a1%e6%81%af/' rel='bookmark' title='Permanent Link: Nagios中用飞信发送报警信息'>Nagios中用飞信发送报警信息</a> <small>近期由于飞信的API变更，原先的Linux版本fetion程序不能再用来发送信息了。而由 flyerhzm 开发的rfetion更新较快，可用来配合Nagios的报警信息发送。 rfetion是基于ruby的一个飞信客户端工具，有命令行的发送模式。使用前，需事先安装好 ruby，及rubygem，相关安装过程在网上有很多。 安装好ruby及rubygem后，可通过如下两行命令来安装rfetion： gem sources -a http://gemcutter.org...</small></li><li><a href='http://blog.enjoyrails.com/2008/12/31/git%e4%b8%80%e5%88%86%e9%92%9f%e6%95%99%e7%a8%8b/' rel='bookmark' title='Permanent Link: Git一分钟教程'>Git一分钟教程</a> <small>流程：取代码 → 每次工作前更新代码到最新版本 → 修改代码 → 提交代码到服务器 取代码及修改全局设置 设置用户名与邮箱 git...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<h3>介绍</h3>
<blockquote>
<p>satellite is a self-syncing distributed wiki with file uploads and all sorts of other useful features like offline editing.</p>
</blockquote>
<p>主要的特性有：</p>
<ul>
<li>textile的wiki语法</li>
<li>支持文件上传</li>
<li>所有文档基于git存储与管理</li>
<li>离线编辑，并可自动同步到服务器</li>
<li>支持代码高亮</li>
<li>全面快捷键支持</li>
</ul>
<p>经我们测试，用于个人知识管理，非常棒。</p>
<h3>安装</h3>
<ul>
<li>安装 Git! (and Ruby)</li>
</ul>
<ul>
<li>获取代码，原始代码在&#8221;这里&#8221;:http://github.com/kenpratt/satellite/tree/master ，我们fork出了一个版本(http://github.com/holin/satellite/tree/master)，根据中文环境和自己的实际需求增加了一些功能，具体看 <a href='http://enjoyrails.com/wikis/satellit扩展功能'>satellit扩展功能</a>。</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">$ git clone git<span style="color: #000000; font-weight: bold;">@</span>github.com:holin<span style="color: #000000; font-weight: bold;">/</span>satellite.git satellite</pre></td></tr></table></div>

<ul>
<li>安装gems， {color:red}注意 ，rack要求使用0.4版本（其它版本未完整测试，最新的0.9rack不能用）</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> rack mongrel metaid erubis RedCloth coderay
 $ <span style="color: #7a0874; font-weight: bold;">cd</span> path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>satellite
 $ git submodule init
 $ git submodule update</pre></td></tr></table></div>

<ul>
<li>配置应用，下方其他中有公开git repository申请说明</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>satellite</pre></td></tr></table></div>

<ul>
<li>edit conf/production.rb</li>
<li><strong><em style="color:red;">production.rb</em></strong> example</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># production configuration</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># URI of master git repository for wiki content</span>
config.<span style="color:#9900CC;">master_repository_uri</span> = <span style="color:#996600;">'git+ssh://repo.or.cz/srv/git/pkmh.git'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># user information to use for git content submissions</span>
config.<span style="color:#9900CC;">user_name</span> = <span style="color:#996600;">'holin'</span>
config.<span style="color:#9900CC;">user_email</span> = <span style="color:#996600;">'holin@example.com'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># logging level (:error, :warn, :info, :debug)</span>
config.<span style="color:#9900CC;">log_level</span> = <span style="color:#ff3333; font-weight:bold;">:warn</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># automatically reload app when app files change? (for development)</span>
config.<span style="color:#9900CC;">auto_reload</span> = <span style="color:#0000FF; font-weight:bold;">true</span></pre></td></tr></table></div>

<ul>
<li>启动server</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">$ bin<span style="color: #000000; font-weight: bold;">/</span>start_satellite  
<span style="color: #000000; font-weight: bold;">**</span> Starting Satellite_2
<span style="color: #000000; font-weight: bold;">**</span> Satellite_2 is now running at http:<span style="color: #000000; font-weight: bold;">//</span>0.0.0.0:<span style="color: #000000;">4000</span><span style="color: #000000; font-weight: bold;">/</span></pre></td></tr></table></div>

<ul>
<li>访问http://localhost:4000/</li>
</ul>
<h3>配置文件，initialize中的配置都可以在production.rb里面通过config.xxx = ??? 来配置</h3>
<ul>
<li>lib/configration.rb</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> initialize
    <span style="color:#008000; font-style:italic;"># defaults values</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">app_name</span>               = <span style="color:#996600;">'Satellite'</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">server_ip</span>              = <span style="color:#996600;">'0.0.0.0'</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">server_port</span>            = <span style="color:#006666;">7000</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">master_repository_uri</span>  = <span style="color:#996600;">''</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">user_name</span>              = <span style="color:#996600;">''</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">user_email</span>             = <span style="color:#996600;">''</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">sync_frequency</span>         = <span style="color:#006666;">60</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">app_dir</span>                = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">expand_path</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#996600;">'../'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">conf_dir</span>               = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>app_dir, <span style="color:#996600;">'conf'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">template_dir</span>           = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>app_dir, <span style="color:#996600;">'templates'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">static_dir</span>             = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>app_dir, <span style="color:#996600;">'static'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">log_dir</span>                = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>app_dir, <span style="color:#996600;">'log'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">data_dir</span>               = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>app_dir, <span style="color:#996600;">'data'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">log_level</span>              = <span style="color:#ff3333; font-weight:bold;">:info</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">log_file_name</span>          = <span style="color:#996600;">'app.log'</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">auto_reload</span>            = <span style="color:#0000FF; font-weight:bold;">false</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">prettify_exceptions</span>    = <span style="color:#0000FF; font-weight:bold;">true</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">max_upload_filesize</span>    = <span style="color:#006666;">200</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">authentication</span>         = <span style="color:#0000FF; font-weight:bold;">false</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">authenticator</span>          = <span style="color:#0000FF; font-weight:bold;">nil</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<h3>Mac下配置开机启动</h3>
<ul>
<li>下载 <a href="http://tuppis.com/lingon/">Lingon</a></li>
<li>写启动server脚本satellite.sh</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>:<span style="color: #007800;">$PATH</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>devon<span style="color: #000000; font-weight: bold;">/</span>wiki <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> bin<span style="color: #000000; font-weight: bold;">/</span>start_satellite</pre></td></tr></table></div>

<ul>
<li>运行Lingon，配置User Deamon</li>
<li>注销，并重新登录。测试是否正确配置</li>
</ul>
<h3>其他</h3>
<ul>
<li>申请 <a href="http://repo.or.cz">repo.or.cz</a> 的git服务</li>
<li><a href="http://git.or.cz/gitwiki/GitHosting">GitHosting</a></li>
</ul>
<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=186&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_186" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>Related posts:<ol><li><a href='http://blog.enjoyrails.com/2009/01/07/shoulda-on-rails/' rel='bookmark' title='Permanent Link: shoulda on rails'>shoulda on rails</a> <small>在新项目中配置shoulda rails shoulda_demo -d mysql cd shoulda_demo/ script/plugin install git://github.com/thoughtbot/shoulda.git...</small></li><li><a href='http://blog.enjoyrails.com/2009/12/04/nagios%e4%b8%ad%e7%94%a8%e9%a3%9e%e4%bf%a1%e5%8f%91%e9%80%81%e6%8a%a5%e8%ad%a6%e4%bf%a1%e6%81%af/' rel='bookmark' title='Permanent Link: Nagios中用飞信发送报警信息'>Nagios中用飞信发送报警信息</a> <small>近期由于飞信的API变更，原先的Linux版本fetion程序不能再用来发送信息了。而由 flyerhzm 开发的rfetion更新较快，可用来配合Nagios的报警信息发送。 rfetion是基于ruby的一个飞信客户端工具，有命令行的发送模式。使用前，需事先安装好 ruby，及rubygem，相关安装过程在网上有很多。 安装好ruby及rubygem后，可通过如下两行命令来安装rfetion： gem sources -a http://gemcutter.org...</small></li><li><a href='http://blog.enjoyrails.com/2008/12/31/git%e4%b8%80%e5%88%86%e9%92%9f%e6%95%99%e7%a8%8b/' rel='bookmark' title='Permanent Link: Git一分钟教程'>Git一分钟教程</a> <small>流程：取代码 → 每次工作前更新代码到最新版本 → 修改代码 → 提交代码到服务器 取代码及修改全局设置 设置用户名与邮箱 git...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2009/01/22/satellite-a-self-syncing-distributed-wiki/feed/</wfw:commentRss>
		</item>
		<item>
		<title>shoulda on rails</title>
		<link>http://blog.enjoyrails.com/2009/01/07/shoulda-on-rails/</link>
		<comments>http://blog.enjoyrails.com/2009/01/07/shoulda-on-rails/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 09:41:49 +0000</pubDate>
		<dc:creator>HoLin</dc:creator>
		
		<category><![CDATA[Rails应用]]></category>

		<category><![CDATA[敏捷开发]]></category>

		<category><![CDATA[测试方法]]></category>

		<category><![CDATA[shoulda]]></category>

		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/?p=182</guid>
		<description><![CDATA[在新项目中配置shoulda

1
2
3
4
5
6
7
rails shoulda_demo -d mysql
cd shoulda_demo/
&#160;
script/plugin install git://github.com/thoughtbot/shoulda.git
sudo gem install thoughtbot-factory_girl --source http://gems.github.com
script/plugin install git://github.com/technicalpickles/factory_girl_on_rails.git
script/plugin install git://github.com/hardbap/coulda.git

测试model
生成model

1
script/generate coulda_model subject

写测试代码，编辑文件 test/unit/subject_test.rb

1
2
3
4
5
6
require File.dirname&#40;__FILE__&#41; + '/../test_helper'
&#160;
class SubjectTest &#60; ActiveSupport::TestCase
  should_have_many :questions
  should_require_attributes :name
end

运行测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
HoLin:tiku holin$ rake test
&#40;in /Users/holin/work/kuxuesoft/tiku&#41;
/usr/local/bin/ruby -Ilib:test &#34;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&#34; &#34;test/unit/subject_test.rb&#34; &#34;test/unit/user_test.rb&#34; 
Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader
Started
FF.............
Finished in 0.301899 seconds.
&#160;
  1&#41; Failure:
test: Subject should have many questions. &#40;SubjectTest&#41;
  [...]


Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/07/14/ruby187-and-rails-210-api/' rel='bookmark' title='Permanent Link: Ruby 1.8.7， Rails 2.1.0 API 文档'>Ruby 1.8.7， Rails 2.1.0 API 文档</a> <small>假定rdoc安装在：/usr/local/lib/ruby/1.8/rdoc 1,下载并解压jaxdoc(http://rubyforge.org/projects/jaxdoc/) sudo cp ajax_generator.rb /usr/local/lib/ruby/1.8/rdoc/generators sudo cp -R ajax...</small></li><li><a href='http://blog.enjoyrails.com/2009/05/22/195/' rel='bookmark' title='Permanent Link: Nginx + Passenger 开发Rails应用'>Nginx + Passenger 开发Rails应用</a> <small>在Rails开发过程中，如果同时开发多个项目，需要经常切换，使用 script/server 去启动应用会比较麻烦，而采用nginx(或apache) + passenger可以节约时间，提高效率。 １、安装passenger 下载Passenger，目前最新的版本为2.2.2，并解压到passenger的安装目录： tar xzvf passenger-2.2.2.tar.gz...</small></li><li><a href='http://blog.enjoyrails.com/2009/01/22/satellite-a-self-syncing-distributed-wiki/' rel='bookmark' title='Permanent Link: Satellite: a self-syncing distributed wiki'>Satellite: a self-syncing distributed wiki</a> <small>介绍 satellite is a self-syncing distributed wiki with file uploads...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<h3>在新项目中配置shoulda</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">rails shoulda_demo <span style="color: #660033;">-d</span> mysql
<span style="color: #7a0874; font-weight: bold;">cd</span> shoulda_demo<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>thoughtbot<span style="color: #000000; font-weight: bold;">/</span>shoulda.git
<span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> thoughtbot-factory_girl <span style="color: #660033;">--source</span> http:<span style="color: #000000; font-weight: bold;">//</span>gems.github.com
script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>technicalpickles<span style="color: #000000; font-weight: bold;">/</span>factory_girl_on_rails.git
script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>hardbap<span style="color: #000000; font-weight: bold;">/</span>coulda.git</pre></td></tr></table></div>

<h3>测试model</h3>
<p>生成model</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">script<span style="color: #000000; font-weight: bold;">/</span>generate coulda_model subject</pre></td></tr></table></div>

<p>写测试代码，编辑文件 test/unit/subject_test.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">'/../test_helper'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> SubjectTest <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveSupport::TestCase</span>
  should_have_many <span style="color:#ff3333; font-weight:bold;">:questions</span>
  should_require_attributes <span style="color:#ff3333; font-weight:bold;">:name</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>运行测试</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ rake <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>holin<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>kuxuesoft<span style="color: #000000; font-weight: bold;">/</span>tiku<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/unit/subject_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/unit/user_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
FF.............
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.301899</span> seconds.
&nbsp;
  <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Failure:
<span style="color: #7a0874; font-weight: bold;">test</span>: Subject should have many questions. <span style="color: #7a0874; font-weight: bold;">&#40;</span>SubjectTest<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    ...:
Subject does not have any relationship to questions.
<span style="color: #000000; font-weight: bold;">&lt;</span>nil<span style="color: #000000; font-weight: bold;">&gt;</span> is not true.
&nbsp;
  <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Failure:
<span style="color: #7a0874; font-weight: bold;">test</span>: Subject should require name to be set. <span style="color: #7a0874; font-weight: bold;">&#40;</span>SubjectTest<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    ...:
Subject allowed nil <span style="color: #c20cb9; font-weight: bold;">as</span> a value <span style="color: #000000; font-weight: bold;">for</span> name.
<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">false</span><span style="color: #000000; font-weight: bold;">&gt;</span> is not true.
&nbsp;
<span style="color: #000000;">15</span> tests, <span style="color: #000000;">28</span> assertions, <span style="color: #000000;">2</span> failures, 0 errors
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/home_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/sessions_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/users_controller_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
...............
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.434793</span> seconds.
&nbsp;
<span style="color: #000000;">15</span> tests, <span style="color: #000000;">27</span> assertions, 0 failures, 0 errors
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span>  
Errors running <span style="color: #7a0874; font-weight: bold;">test</span>:units<span style="color: #000000; font-weight: bold;">!</span></pre></td></tr></table></div>

<p>出错，编辑文件 app/models/subject.rb 来让测试通过</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Subject <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:questions</span>
  validates_presence_of <span style="color:#ff3333; font-weight:bold;">:name</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>再次运行测试</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ rake <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>holin<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>kuxuesoft<span style="color: #000000; font-weight: bold;">/</span>tiku<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/unit/subject_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/unit/user_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
E..............
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.333493</span> seconds.
&nbsp;
  <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Error:
<span style="color: #7a0874; font-weight: bold;">test</span>: Subject should have many questions. <span style="color: #7a0874; font-weight: bold;">&#40;</span>SubjectTest<span style="color: #7a0874; font-weight: bold;">&#41;</span>:
NameError: uninitialized constant Question
    ...
&nbsp;
<span style="color: #000000;">15</span> tests, <span style="color: #000000;">31</span> assertions, 0 failures, <span style="color: #000000;">1</span> errors
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/home_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/sessions_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/users_controller_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
...............
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.460992</span> seconds.
&nbsp;
<span style="color: #000000;">15</span> tests, <span style="color: #000000;">27</span> assertions, 0 failures, 0 errors
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span>  
Errors running <span style="color: #7a0874; font-weight: bold;">test</span>:units<span style="color: #000000; font-weight: bold;">!</span></pre></td></tr></table></div>

<p>还是通不过，新建question model</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ script<span style="color: #000000; font-weight: bold;">/</span>generate coulda_model question
      exists  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>
      exists  <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>
      exists  <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">/</span>factories<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>question.rb
      create  <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>question_test.rb
      create  <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">/</span>factories<span style="color: #000000; font-weight: bold;">/</span>question_factory.rb
      exists  db<span style="color: #000000; font-weight: bold;">/</span>migrate
      create  db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20090107064242</span>_create_questions.rb</pre></td></tr></table></div>

<p>运行测试</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ rake <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>holin<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>kuxuesoft<span style="color: #000000; font-weight: bold;">/</span>tiku<span style="color: #7a0874; font-weight: bold;">&#41;</span>
You have <span style="color: #000000;">1</span> pending migrations:
  <span style="color: #000000;">20090107064242</span> CreateQuestions
Run <span style="color: #ff0000;">&quot;rake db:migrate&quot;</span> to update your database <span style="color: #000000; font-weight: bold;">then</span> try again.</pre></td></tr></table></div>

<p>需要先完成所有的Migration，那就完成他们吧。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ rake db:migrate
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>holin<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>kuxuesoft<span style="color: #000000; font-weight: bold;">/</span>tiku<span style="color: #7a0874; font-weight: bold;">&#41;</span>
==  CreateQuestions: migrating ================================================
<span style="color: #660033;">--</span> create_table<span style="color: #7a0874; font-weight: bold;">&#40;</span>:questions<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   -<span style="color: #000000; font-weight: bold;">&gt;</span> 0.0347s
==  CreateQuestions: migrated <span style="color: #7a0874; font-weight: bold;">&#40;</span>0.0351s<span style="color: #7a0874; font-weight: bold;">&#41;</span> =======================================</pre></td></tr></table></div>

<p>再运行测试</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ rake <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>holin<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>kuxuesoft<span style="color: #000000; font-weight: bold;">/</span>tiku<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/unit/question_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/unit/subject_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/unit/user_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
...............
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.323642</span> seconds.
&nbsp;
<span style="color: #000000;">15</span> tests, <span style="color: #000000;">32</span> assertions, 0 failures, 0 errors
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/home_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/sessions_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/users_controller_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
...............
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.438684</span> seconds.
&nbsp;
<span style="color: #000000;">15</span> tests, <span style="color: #000000;">27</span> assertions, 0 failures, 0 errors
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span></pre></td></tr></table></div>

<p>通过测试</p>
<h3>测试controller</h3>
<p>生成controller</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ script<span style="color: #000000; font-weight: bold;">/</span>generate controller subjects
      exists  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>
      exists  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>views<span style="color: #000000; font-weight: bold;">/</span>subjects
      exists  <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>
      create  app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>subjects_controller.rb
      create  <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>subjects_controller_test.rb
      create  app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>subjects_helper.rb</pre></td></tr></table></div>

<p>编写测试代码，编辑文件test/functional/subjects_controller_test.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'test_helper'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> SubjectsControllerTest <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::TestCase</span>
&nbsp;
  context <span style="color:#996600;">&quot;on POST to :create&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    setup <span style="color:#006600; font-weight:bold;">&#123;</span> post <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:subject</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:name <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'CET－6'</span>, <span style="color:#ff3333; font-weight:bold;">:desc</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'description goes here'</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    should_assign_to <span style="color:#ff3333; font-weight:bold;">:subject</span>
    should_redirect_to <span style="color:#996600;">&quot;subject_url(@subject)&quot;</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>运行测试</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ rake <span style="color: #7a0874; font-weight: bold;">test</span>:functionals
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>holin<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>kuxuesoft<span style="color: #000000; font-weight: bold;">/</span>tiku<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/home_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/sessions_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/subjects_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/users_controller_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
..........FE.....
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.603312</span> seconds.
&nbsp;
  <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Failure:
<span style="color: #7a0874; font-weight: bold;">test</span>: on POST to :create should assign <span style="color: #000000; font-weight: bold;">@</span>subject. <span style="color: #7a0874; font-weight: bold;">&#40;</span>SubjectsControllerTest<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span>:
The action isn<span style="color: #ff0000;">'t assigning to @subject.
&lt;nil&gt; expected to not be nil.
&nbsp;
  2) Error:
test: on POST to :create should redirect to &quot;subject_url(@subject)&quot;. (SubjectsControllerTest):
NoMethodError: undefined method `subject_url'</span> <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #666666; font-style: italic;">#&lt;SubjectsControllerTest:0x227f428&gt;</span>
    ...
&nbsp;
<span style="color: #000000;">17</span> tests, <span style="color: #000000;">28</span> assertions, <span style="color: #000000;">1</span> failures, <span style="color: #000000;">1</span> errors
rake aborted<span style="color: #000000; font-weight: bold;">!</span>
Command failed with status <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local...]
&nbsp;
(See full trace by running task with --trace)</span></pre></td></tr></table></div>

<p>添加routes</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby ruby" style="font-family:monospace;">map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:subjects</span></pre></td></tr></table></div>

<p>运行测试</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ rake <span style="color: #7a0874; font-weight: bold;">test</span>:functionals
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>holin<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>kuxuesoft<span style="color: #000000; font-weight: bold;">/</span>tiku<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/home_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/sessions_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/subjects_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/users_controller_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
..........FE.....
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.536594</span> seconds.
&nbsp;
  <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Failure:
<span style="color: #7a0874; font-weight: bold;">test</span>: on POST to :create should assign <span style="color: #000000; font-weight: bold;">@</span>subject. <span style="color: #7a0874; font-weight: bold;">&#40;</span>SubjectsControllerTest<span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">&#91;</span>...<span style="color: #7a0874; font-weight: bold;">&#93;</span>:
The action isn<span style="color: #ff0000;">'t assigning to @subject.
&lt;nil&gt; expected to not be nil.
&nbsp;
  2) Error:
test: on POST to :create should redirect to &quot;subject_url(@subject)&quot;. (SubjectsControllerTest):
ActionController::RoutingError: subject_url failed to generate from {:controller=&gt;&quot;subjects&quot;, :action=&gt;&quot;show&quot;, :id=&gt;nil}, expected: {:controller=&gt;&quot;subjects&quot;, :action=&gt;&quot;show&quot;}, diff: {:id=&gt;nil}
    ...
&nbsp;
17 tests, 28 assertions, 1 failures, 1 errors
rake aborted!
Command failed with status (1): [/usr/local/bin/ruby -Ilib:test &quot;/usr/local...]
&nbsp;
(See full trace by running task with --trace)</span></pre></td></tr></table></div>

<p>编辑app/controllers/subjects_controller.rb， 增加create action</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> SubjectsController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> create
    <span style="color:#0066ff; font-weight:bold;">@subject</span> = Subject.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:subject</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@subject</span>.<span style="color:#9900CC;">valid</span>? <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#0066ff; font-weight:bold;">@subject</span>.<span style="color:#9900CC;">save</span>
      flash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:message</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;添加成功&quot;</span>
      redirect_to subject_url<span style="color:#006600; font-weight:bold;">&#40;</span>@subject<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      render <span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'new'</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>运行测试</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ rake <span style="color: #7a0874; font-weight: bold;">test</span>:functionals
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>holin<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>kuxuesoft<span style="color: #000000; font-weight: bold;">/</span>tiku<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/home_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/sessions_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/subjects_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/users_controller_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
.................
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.687698</span> seconds.
&nbsp;
<span style="color: #000000;">17</span> tests, <span style="color: #000000;">29</span> assertions, 0 failures, 0 errors</pre></td></tr></table></div>

<p>测试通过</p>
<h3>测试需要登陆的操作、嵌套context</h3>
<p>编写测试代码，编辑文件test/functional/subjects_controller_test.rb</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="ruby ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'test_helper'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> SubjectsControllerTest <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActionController::TestCase</span>
&nbsp;
  context <span style="color:#996600;">&quot;do these after logged in&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
    setup <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#0066ff; font-weight:bold;">@request</span>.<span style="color:#9900CC;">session</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:user_id</span><span style="color:#006600; font-weight:bold;">&#93;</span> = User.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">id</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
    context <span style="color:#996600;">&quot;on POST to :create&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      setup <span style="color:#006600; font-weight:bold;">&#123;</span> 
        post <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:subject</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:name <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'CET－6'</span>, <span style="color:#ff3333; font-weight:bold;">:desc</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'description goes here'</span> <span style="color:#006600; font-weight:bold;">&#125;</span> 
      <span style="color:#006600; font-weight:bold;">&#125;</span>
      should_assign_to <span style="color:#ff3333; font-weight:bold;">:subject</span>
      should_redirect_to <span style="color:#996600;">&quot;subject_url(@subject)&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    context <span style="color:#996600;">&quot;on POST to :create without subject name&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      setup <span style="color:#006600; font-weight:bold;">&#123;</span> 
        post <span style="color:#ff3333; font-weight:bold;">:create</span>, <span style="color:#ff3333; font-weight:bold;">:subject</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:desc <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'description goes here'</span> <span style="color:#006600; font-weight:bold;">&#125;</span> 
      <span style="color:#006600; font-weight:bold;">&#125;</span>
      should_assign_to <span style="color:#ff3333; font-weight:bold;">:subject</span>
      should_redirect_to <span style="color:#996600;">&quot;new_subject_url&quot;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>运行测试</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash bash" style="font-family:monospace;">HoLin:tiku holin$ rake <span style="color: #7a0874; font-weight: bold;">test</span>:functionals
<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>holin<span style="color: #000000; font-weight: bold;">/</span>work<span style="color: #000000; font-weight: bold;">/</span>kuxuesoft<span style="color: #000000; font-weight: bold;">/</span>tiku<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ruby -Ilib:<span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #ff0000;">&quot;/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake/rake_test_loader.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/home_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/sessions_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/subjects_controller_test.rb&quot;</span> <span style="color: #ff0000;">&quot;test/functional/users_controller_test.rb&quot;</span> 
Loaded suite <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>ruby<span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.8</span><span style="color: #000000; font-weight: bold;">/</span>gems<span style="color: #000000; font-weight: bold;">/</span>rake-0.8.3<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>rake<span style="color: #000000; font-weight: bold;">/</span>rake_test_loader
Started
...................
Finished <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">0.572731</span> seconds.
&nbsp;
<span style="color: #000000;">19</span> tests, <span style="color: #000000;">31</span> assertions, 0 failures, 0 errors</pre></td></tr></table></div>

<h3>参考资源</h3>
<ul>
<li><a href="http://thoughtbot.com/projects/shoulda/tutorial">Shoulda tutorials</a></li>
<li><a href="http://alexbrie.net/1526/functional-tests-with-login-in-rails/">Functional tests with login in Rails</a></li>
</ul>
<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=182&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_182" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/07/14/ruby187-and-rails-210-api/' rel='bookmark' title='Permanent Link: Ruby 1.8.7， Rails 2.1.0 API 文档'>Ruby 1.8.7， Rails 2.1.0 API 文档</a> <small>假定rdoc安装在：/usr/local/lib/ruby/1.8/rdoc 1,下载并解压jaxdoc(http://rubyforge.org/projects/jaxdoc/) sudo cp ajax_generator.rb /usr/local/lib/ruby/1.8/rdoc/generators sudo cp -R ajax...</small></li><li><a href='http://blog.enjoyrails.com/2009/05/22/195/' rel='bookmark' title='Permanent Link: Nginx + Passenger 开发Rails应用'>Nginx + Passenger 开发Rails应用</a> <small>在Rails开发过程中，如果同时开发多个项目，需要经常切换，使用 script/server 去启动应用会比较麻烦，而采用nginx(或apache) + passenger可以节约时间，提高效率。 １、安装passenger 下载Passenger，目前最新的版本为2.2.2，并解压到passenger的安装目录： tar xzvf passenger-2.2.2.tar.gz...</small></li><li><a href='http://blog.enjoyrails.com/2009/01/22/satellite-a-self-syncing-distributed-wiki/' rel='bookmark' title='Permanent Link: Satellite: a self-syncing distributed wiki'>Satellite: a self-syncing distributed wiki</a> <small>介绍 satellite is a self-syncing distributed wiki with file uploads...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2009/01/07/shoulda-on-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Git服务器安装</title>
		<link>http://blog.enjoyrails.com/2009/01/06/git%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%ae%89%e8%a3%85/</link>
		<comments>http://blog.enjoyrails.com/2009/01/06/git%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%ae%89%e8%a3%85/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 04:38:24 +0000</pubDate>
		<dc:creator>devon</dc:creator>
		
		<category><![CDATA[源代码管理]]></category>

		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/?p=174</guid>
		<description><![CDATA[Git on Ubuntu Server
安装Git-Core:

1
2
3
4
sudo apt-get update # 可选步骤
sudo apt-get dist-upgrade # 可选步骤
&#160;
sudo apt-get install git-core

因为要用到 Gitosis ，所有，需要安装python setuptools

1
sudo apt-get install python-setuptools

安装 Gitosis

1
2
3
4
5
6
mkdir ~/src
cd ~/src
git clone git://eagain.net/gitosis
&#160;
cd gitosis
sudo python setup.py install

增加名为Git的用户

1
sudo adduser --system --shell /bin/sh  --gecos 'git version control' --group --disabled-password --home /home/git git

上传公钥到USER用户的根目录下（如果没有，用 ssh-keygen -t rsa 生成）

1
2
3
scp .ssh/id_rsa.pub USER@YOUR_SERVER:
sudo -H -u git gitosis-init &#60; [...]


Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/12/28/git%e8%af%a6%e8%a7%a3%ef%bc%88%e4%b8%80%ef%bc%89/' rel='bookmark' title='Permanent Link: Git详解（一）'>Git详解（一）</a> <small>我用git最开始是在github，每次提交代码以后，右上角的部分就会显示这些信息，类似于下面的： commit  fa6f27b7de063c2f301b0e7148b5bd5e813faa98 tree       5e7a19c158b89fbc52a078771a833ee839727404 parent   76f31606376180ca88efa12be341dbb14fb06fdf 咋一看，这40位的乱码挺吓人的，但是你了解它的作用就不会被吓到了。 这是object name，是作为你每次提交的信息标识。这是用SHA1加密hash函数根据你的对象的内容算出来的。Git的一些优点：...</small></li><li><a href='http://blog.enjoyrails.com/2008/12/31/git%e4%b8%80%e5%88%86%e9%92%9f%e6%95%99%e7%a8%8b/' rel='bookmark' title='Permanent Link: Git一分钟教程'>Git一分钟教程</a> <small>流程：取代码 → 每次工作前更新代码到最新版本 → 修改代码 → 提交代码到服务器 取代码及修改全局设置 设置用户名与邮箱 git...</small></li><li><a href='http://blog.enjoyrails.com/2008/12/30/git%e8%af%a6%e8%a7%a3%ef%bc%88%e4%ba%8c%ef%bc%89/' rel='bookmark' title='Permanent Link: Git详解（二）'>Git详解（二）</a> <small>Git中级用法： Ignoring files 项目里总会出现你不想跟踪的文件。当然这些文件你不对它们进行git add操作就行了，但是这样也很麻烦， 如果使用git add .命令和git commit -a命令呢？你能告诉git去忽略一些文件，我们只需要在我们工作目录顶级创建一个.gitignore文件就可以了。就像这样：...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<h3>Git on Ubuntu Server</h3>
<p>安装Git-Core:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">sudo apt<span style="color:#006600; font-weight:bold;">-</span>get <span style="color:#5A0A0A; font-weight:bold;">update</span> <span style="color:#008000; font-style:italic;"># 可选步骤</span>
sudo apt<span style="color:#006600; font-weight:bold;">-</span>get dist<span style="color:#006600; font-weight:bold;">-</span>upgrade <span style="color:#008000; font-style:italic;"># 可选步骤</span>
&nbsp;
sudo apt<span style="color:#006600; font-weight:bold;">-</span>get install git<span style="color:#006600; font-weight:bold;">-</span>core</pre></td></tr></table></div>

<p>因为要用到 <a href="http://eagain.net/gitweb/?p=gitosis.git;a=blob;f=README.rst">Gitosis</a> ，所有，需要安装python setuptools</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">sudo apt<span style="color:#006600; font-weight:bold;">-</span>get install python<span style="color:#006600; font-weight:bold;">-</span>setuptools</pre></td></tr></table></div>

<p>安装 Gitosis</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">mkdir ~<span style="color:#006600; font-weight:bold;">/</span>src
cd ~<span style="color:#006600; font-weight:bold;">/</span>src
git <span style="color:#5A0A0A; font-weight:bold;">clone</span> git:<span style="color:#006600; font-weight:bold;">//</span>eagain.<span style="color:#9900CC;">net</span><span style="color:#006600; font-weight:bold;">/</span>gitosis
&nbsp;
cd gitosis
sudo python setup.<span style="color:#9900CC;">py</span> install</pre></td></tr></table></div>

<p>增加名为Git的用户</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">sudo adduser <span style="color:#006600; font-weight:bold;">--</span><span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#006600; font-weight:bold;">--</span>shell <span style="color:#006600; font-weight:bold;">/</span>bin<span style="color:#006600; font-weight:bold;">/</span>sh  <span style="color:#006600; font-weight:bold;">--</span>gecos <span style="color:#996600;">'git version control'</span> <span style="color:#006600; font-weight:bold;">--</span>group <span style="color:#006600; font-weight:bold;">--</span>disabled<span style="color:#006600; font-weight:bold;">-</span>password <span style="color:#006600; font-weight:bold;">--</span>home <span style="color:#006600; font-weight:bold;">/</span>home<span style="color:#006600; font-weight:bold;">/</span>git git</pre></td></tr></table></div>

<p>上传公钥到USER用户的根目录下（如果没有，用 ssh-keygen -t rsa 生成）</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">scp .<span style="color:#9900CC;">ssh</span><span style="color:#006600; font-weight:bold;">/</span>id_rsa.<span style="color:#9900CC;">pub</span> USER@YOUR_SERVER:
sudo <span style="color:#006600; font-weight:bold;">-</span>H <span style="color:#006600; font-weight:bold;">-</span>u git gitosis<span style="color:#006600; font-weight:bold;">-</span>init <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">/</span>home<span style="color:#006600; font-weight:bold;">/</span>USER<span style="color:#006600; font-weight:bold;">/</span>id_rsa.<span style="color:#9900CC;">pub</span>
sudo chmod <span style="color:#006666;">755</span> <span style="color:#006600; font-weight:bold;">/</span>home<span style="color:#006600; font-weight:bold;">/</span>git<span style="color:#006600; font-weight:bold;">/</span>repositories<span style="color:#006600; font-weight:bold;">/</span>gitosis<span style="color:#006600; font-weight:bold;">-</span>admin.<span style="color:#9900CC;">git</span><span style="color:#006600; font-weight:bold;">/</span>hooks<span style="color:#006600; font-weight:bold;">/</span>post<span style="color:#006600; font-weight:bold;">-</span><span style="color:#5A0A0A; font-weight:bold;">update</span></pre></td></tr></table></div>

<p>到这一步，基本上都安装好了，到本地进行测试：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">git <span style="color:#5A0A0A; font-weight:bold;">clone</span> git@YOUR_SERVER:gitosis<span style="color:#006600; font-weight:bold;">-</span>admin.<span style="color:#9900CC;">git</span></pre></td></tr></table></div>

<p>成功后，在本地将有一个gitosis-admin目录，里面有gitosis.conf，keydir。</p>
<p>为Rails项目配置git<br />
打开gitosis.conf，增加一块内容，members为某个用户的公钥~/.ssh/id_rsa.pub中的名字（在该文件的最后在）</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#91;</span>group myrailsapp<span style="color:#006600; font-weight:bold;">&#93;</span>
members = vince@urbanpuddle
writable = myrailsapp</pre></td></tr></table></div>

<p>然后，提交修改</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">git commit <span style="color:#006600; font-weight:bold;">-</span>a <span style="color:#006600; font-weight:bold;">-</span>m <span style="color:#996600;">&quot;created a new repository&quot;</span>
git push</pre></td></tr></table></div>

<p>将本地代码提交到git中</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">cd myrailsapp
git init</pre></td></tr></table></div>

<p>创建 .gitignore 文件，用于忽略某些不需要进行代码管理的内容</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">.<span style="color:#9900CC;">DS_Store</span>
log<span style="color:#006600; font-weight:bold;">/*</span>.<span style="color:#9900CC;">log</span>
tmp<span style="color:#006600; font-weight:bold;">/**/*</span>
config<span style="color:#006600; font-weight:bold;">/</span>database.<span style="color:#9900CC;">yml</span>
db<span style="color:#006600; font-weight:bold;">/*</span>.<span style="color:#9900CC;">sqlite3</span></pre></td></tr></table></div>

<p>提交代码</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">git remote <span style="color:#5A0A0A; font-weight:bold;">add</span> origin git@YOUR_SERVER:myrailsapp.<span style="color:#9900CC;">git</span>
git <span style="color:#5A0A0A; font-weight:bold;">add</span> .
<span style="color:#9900CC;">git</span> commit <span style="color:#006600; font-weight:bold;">-</span>a <span style="color:#006600; font-weight:bold;">-</span>m <span style="color:#996600;">&quot;initial import&quot;</span>
git push origin master:refs<span style="color:#006600; font-weight:bold;">/</span>heads<span style="color:#006600; font-weight:bold;">/</span>master</pre></td></tr></table></div>

<p>接下来，可以增加成员的公钥到系统中了</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">cd gitosis<span style="color:#006600; font-weight:bold;">-</span>admin
cp ~<span style="color:#006600; font-weight:bold;">/</span>alice.<span style="color:#9900CC;">pub</span> keydir<span style="color:#006600; font-weight:bold;">/</span>
cp ~<span style="color:#006600; font-weight:bold;">/</span>bob.<span style="color:#9900CC;">pub</span> keydir<span style="color:#006600; font-weight:bold;">/</span>
git <span style="color:#5A0A0A; font-weight:bold;">add</span> keydir<span style="color:#006600; font-weight:bold;">/</span>alice.<span style="color:#9900CC;">pub</span> keydir<span style="color:#006600; font-weight:bold;">/</span>bob.<span style="color:#9900CC;">pub</span></pre></td></tr></table></div>

<p>修改gitosis.conf</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#91;</span>group myteam<span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">-</span> members = jdoe
<span style="color:#006600; font-weight:bold;">+</span> members = jdoe alice bob
  writable = free_monkey</pre></td></tr></table></div>

<p>提交修改</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">git commit <span style="color:#006600; font-weight:bold;">-</span>a <span style="color:#006600; font-weight:bold;">-</span>m <span style="color:#996600;">&quot;Granted Alice and Bob commit rights to FreeMonkey&quot;</span>
git push</pre></td></tr></table></div>

<p>其它成员就可以获取代码了</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">git <span style="color:#5A0A0A; font-weight:bold;">clone</span> git@YOUR_SERVER:myrailsapp.<span style="color:#9900CC;">git</span></pre></td></tr></table></div>

<p>请参考 <a href="http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way">Hosting Git repositories, The Easy (and Secure) Way</a></p>
<p>原文请参考 : <a href="http://enjoyrails.com/wikis/Git安装">http://enjoyrails.com/wikis/Git安装</a></p>
<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=174&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_174" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/12/28/git%e8%af%a6%e8%a7%a3%ef%bc%88%e4%b8%80%ef%bc%89/' rel='bookmark' title='Permanent Link: Git详解（一）'>Git详解（一）</a> <small>我用git最开始是在github，每次提交代码以后，右上角的部分就会显示这些信息，类似于下面的： commit  fa6f27b7de063c2f301b0e7148b5bd5e813faa98 tree       5e7a19c158b89fbc52a078771a833ee839727404 parent   76f31606376180ca88efa12be341dbb14fb06fdf 咋一看，这40位的乱码挺吓人的，但是你了解它的作用就不会被吓到了。 这是object name，是作为你每次提交的信息标识。这是用SHA1加密hash函数根据你的对象的内容算出来的。Git的一些优点：...</small></li><li><a href='http://blog.enjoyrails.com/2008/12/31/git%e4%b8%80%e5%88%86%e9%92%9f%e6%95%99%e7%a8%8b/' rel='bookmark' title='Permanent Link: Git一分钟教程'>Git一分钟教程</a> <small>流程：取代码 → 每次工作前更新代码到最新版本 → 修改代码 → 提交代码到服务器 取代码及修改全局设置 设置用户名与邮箱 git...</small></li><li><a href='http://blog.enjoyrails.com/2008/12/30/git%e8%af%a6%e8%a7%a3%ef%bc%88%e4%ba%8c%ef%bc%89/' rel='bookmark' title='Permanent Link: Git详解（二）'>Git详解（二）</a> <small>Git中级用法： Ignoring files 项目里总会出现你不想跟踪的文件。当然这些文件你不对它们进行git add操作就行了，但是这样也很麻烦， 如果使用git add .命令和git commit -a命令呢？你能告诉git去忽略一些文件，我们只需要在我们工作目录顶级创建一个.gitignore文件就可以了。就像这样：...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2009/01/06/git%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%ae%89%e8%a3%85/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rails中检测SWF尺寸</title>
		<link>http://blog.enjoyrails.com/2009/01/05/rails%e4%b8%ad%e6%a3%80%e6%b5%8bswf%e5%b0%ba%e5%af%b8/</link>
		<comments>http://blog.enjoyrails.com/2009/01/05/rails%e4%b8%ad%e6%a3%80%e6%b5%8bswf%e5%b0%ba%e5%af%b8/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 07:36:10 +0000</pubDate>
		<dc:creator>devon</dc:creator>
		
		<category><![CDATA[Rails应用]]></category>

		<category><![CDATA[Plugin]]></category>

		<category><![CDATA[swf]]></category>

		<guid isPermaLink="false">http://blog.enjoyrails.com/?p=171</guid>
		<description><![CDATA[安装：

1
2
cd vendor/plugins
svn export http://ruby-imagespec.googlecode.com/svn/trunk/ image_spec

使用：

1
2
3
4
image = ImageSpec::Dimensions.new&#40;'/path/to/your/file'&#41;
&#160;
image.width
image.height

例子：

1
2
3
4
5
6
&#62;&#62; image = ImageSpec::Dimensions.new&#40;&#34;#{RAILS_ROOT}/a.swf&#34;&#41;
=&#62; #&#60;ImageSpec::Dimensions:0x2570d94 @height=670, @width=868&#62;
&#62;&#62; image.width
=&#62; 868
&#62;&#62; image.height
=&#62; 670

收藏、分享这篇文章!


Related posts:Rails应用添加配置的方法 方法一： 使用 app_config 插件 script/plugin install http://svn.jarmark.org/rails/app_config Rails::Initializer.run do &#124;config&#124;...Rails PDF 输出 Rails中生成PDF有多种办法，HTMLDOC命令（可配合HTML，CSS将页面转成PDF）、PDF::Writer、Ruby FPDF。本文以Ruby FPDF为例，讲解如何在Rails输出中英文的PDF文档。 1, 安装 railsrfpdf 插件 ruby script/plugin install...
Related posts brought to you by Yet Another Related Posts Plugin.


Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/06/12/rails%e5%ba%94%e7%94%a8%e6%b7%bb%e5%8a%a0%e9%85%8d%e7%bd%ae%e7%9a%84%e6%96%b9%e6%b3%95/' rel='bookmark' title='Permanent Link: Rails应用添加配置的方法'>Rails应用添加配置的方法</a> <small>方法一： 使用 app_config 插件 script/plugin install http://svn.jarmark.org/rails/app_config Rails::Initializer.run do |config|...</small></li><li><a href='http://blog.enjoyrails.com/2007/12/19/generate-pdfs-in-ruby-on-rails/' rel='bookmark' title='Permanent Link: Rails PDF 输出'>Rails PDF 输出</a> <small>Rails中生成PDF有多种办法，HTMLDOC命令（可配合HTML，CSS将页面转成PDF）、PDF::Writer、Ruby FPDF。本文以Ruby FPDF为例，讲解如何在Rails输出中英文的PDF文档。 1, 安装 railsrfpdf 插件 ruby script/plugin install...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>安装：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">cd vendor<span style="color:#006600; font-weight:bold;">/</span>plugins
svn export http:<span style="color:#006600; font-weight:bold;">//</span>ruby<span style="color:#006600; font-weight:bold;">-</span>imagespec.<span style="color:#9900CC;">googlecode</span>.<span style="color:#9900CC;">com</span><span style="color:#006600; font-weight:bold;">/</span>svn<span style="color:#006600; font-weight:bold;">/</span>trunk<span style="color:#006600; font-weight:bold;">/</span> image_spec</pre></td></tr></table></div>

<p>使用：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;">image = <span style="color:#6666ff; font-weight:bold;">ImageSpec::Dimensions</span>.<span style="color:#5A0A0A; font-weight:bold;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/path/to/your/file'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
image.<span style="color:#9900CC;">width</span>
image.<span style="color:#9900CC;">height</span></pre></td></tr></table></div>

<p>例子：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="rails rails" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> image = <span style="color:#6666ff; font-weight:bold;">ImageSpec::Dimensions</span>.<span style="color:#5A0A0A; font-weight:bold;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;#{RAILS_ROOT}/a.swf&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#008000; font-style:italic;">#&lt;ImageSpec::Dimensions:0x2570d94 @height=670, @width=868&gt;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> image.<span style="color:#9900CC;">width</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">868</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> image.<span style="color:#9900CC;">height</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">670</span></pre></td></tr></table></div>

<p class="akst_link"><a href="http://blog.enjoyrails.com/?p=171&amp;akst_action=share-this"  title="可以通过E-mail分享, 用del.icio.us、Google等网络书签收藏！" id="akst_link_171" class="akst_share_link" rel="nofollow">收藏、分享这篇文章!</a>
</p>

<p>Related posts:<ol><li><a href='http://blog.enjoyrails.com/2008/06/12/rails%e5%ba%94%e7%94%a8%e6%b7%bb%e5%8a%a0%e9%85%8d%e7%bd%ae%e7%9a%84%e6%96%b9%e6%b3%95/' rel='bookmark' title='Permanent Link: Rails应用添加配置的方法'>Rails应用添加配置的方法</a> <small>方法一： 使用 app_config 插件 script/plugin install http://svn.jarmark.org/rails/app_config Rails::Initializer.run do |config|...</small></li><li><a href='http://blog.enjoyrails.com/2007/12/19/generate-pdfs-in-ruby-on-rails/' rel='bookmark' title='Permanent Link: Rails PDF 输出'>Rails PDF 输出</a> <small>Rails中生成PDF有多种办法，HTMLDOC命令（可配合HTML，CSS将页面转成PDF）、PDF::Writer、Ruby FPDF。本文以Ruby FPDF为例，讲解如何在Rails输出中英文的PDF文档。 1, 安装 railsrfpdf 插件 ruby script/plugin install...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.enjoyrails.com/2009/01/05/rails%e4%b8%ad%e6%a3%80%e6%b5%8bswf%e5%b0%ba%e5%af%b8/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
