<?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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>船长日志 &#187; rubyonrails</title>
	<atom:link href="http://www.cslog.cn/tag/rubyonrails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cslog.cn</link>
	<description>最让我激动的是不知道下一个星球上能发现什么...</description>
	<lastBuildDate>Wed, 30 Jul 2025 16:06:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>mysql不能储存生僻汉字？试试utf8mb4字符集</title>
		<link>http://www.cslog.cn/Content/mysql-utf8mb4/</link>
		<comments>http://www.cslog.cn/Content/mysql-utf8mb4/#comments</comments>
		<pubDate>Fri, 07 Jun 2013 15:13:29 +0000</pubDate>
		<dc:creator>船长</dc:creator>
				<category><![CDATA[信息处理]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[utf8]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[汉字]]></category>
		<category><![CDATA[汉字编码]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=1165</guid>
		<description><![CDATA[今天发现存进mysql的数据部分丢失了。发现丢失的都是一些生僻的汉字。我这个my &#8230; <a href="http://www.cslog.cn/Content/mysql-utf8mb4/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>今天发现存进mysql的数据部分丢失了。发现丢失的都是一些生僻的汉字。我这个mysql使用的是utf8字符集，之前一直以为不会发生这种问题，今天才看到了。而且这个问题<a href="http://bbs.zdic.net/thread-115854-1-1.html">很早就存在了</a>。这是<a href="http://bugs.mysql.com/bug.php?id=14052">mysql的一个bug</a>，它的UTF-8字符集只能存储3字节字符，而有部分生僻的汉字是4个字节的，存入时就会出错：</p>
<blockquote><p>ActiveRecord::StatementInvalid: Mysql::Error: Incorrect string value: &#8216;\xF0\x90\x8D\x83\xF0\x90&#8230;&#8217; for column &#8216;content&#8217; at row 1</p></blockquote>
<p>上面的官方bug页面说要到mysql6.0才会解决。其实这个问题在mysql 5.5就解决了。5.5或以上的mysql都可以通过使用utf-16或utf8mb4等字符集解决这个问题。</p>
<p>不过使用ruby on rails的话可能<a href="http://donpark.org/blog/2013/02/16/rails-3-2-12-not-ready-for-mysql-5-5-utf8mb4">需要一些额外的设置</a>。
<div style="margin-top: 15px; font-style: italic">
<p>转载请注明: 转自<a href="http://www.cslog.cn/">船长日志</a>, 本文链接地址: <a href="http://www.cslog.cn/Content/mysql-utf8mb4/">http://www.cslog.cn/Content/mysql-utf8mb4/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/mysql-utf8mb4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>太恶心了&#8211; rubygems安装gem需要使用代理服务器了</title>
		<link>http://www.cslog.cn/Content/g-f-w-ni-ma-de/</link>
		<comments>http://www.cslog.cn/Content/g-f-w-ni-ma-de/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 07:43:14 +0000</pubDate>
		<dc:creator>船长</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[privoxy]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubygems]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=887</guid>
		<description><![CDATA[换了一台电脑，想用rubygems重新安装rails，但一直遇到各种如问题： s &#8230; <a href="http://www.cslog.cn/Content/g-f-w-ni-ma-de/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>换了一台电脑，想用rubygems重新安装rails，但一直遇到各种如问题：</p>
<pre>sudo gem install -v=2.3.9 rails
Password:
ERROR:  Could not find a valid gem 'rails' (= 2.3.9) in any repository
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    too many connection resets (http://production.s3.rubygems.org/latest_specs.4.8.gz)</pre>
<p>或</p>
<pre>ERROR: While executing gem ... (Gem::DependencyError)
  Unable to resolve dependencies: rails requires activesupport (= 3.0.5), actionpack (= 3.0.5), activerecord (= 3.0.5), activeresource (= 3.0.5), actionmailer (= 3.0.5), railties (= 3.0.5), bundler (~&gt; 1.0)</pre>
<p>google了半天（期间google中短NNN次），才明天了现在<a href="http://hi.baidu.com/sitoto/blog/item/d00fd658fa6f469c810a181e.html">使用rubygems 安装gem也得开代理了</a>。。。</p>
<p>要使用加了代理的命令：</p>
<pre>sudo gem install rails -p http://127.0.0.1:8118</pre>
<p>现在rubygems好像只支持http代理。 如果你使用的是socks代理，可以通过Privoxy（支持linux和mac)这个软件来搞一个http代理 通道， 详细参看<a href="http://www.cnblogs.com/another-wheel/archive/2011/11/16/setup-http-proxy-via-socks-and-privoxy.html">这个教程</a>。
<div style="margin-top: 15px; font-style: italic">
<p>转载请注明: 转自<a href="http://www.cslog.cn/">船长日志</a>, 本文链接地址: <a href="http://www.cslog.cn/Content/g-f-w-ni-ma-de/">http://www.cslog.cn/Content/g-f-w-ni-ma-de/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/g-f-w-ni-ma-de/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>使用Unicorn替代Mongrel作为Ruby on Rails的服务器</title>
		<link>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/</link>
		<comments>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 16:54:41 +0000</pubDate>
		<dc:creator>船长</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[站长文档]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[unicorn]]></category>
		<category><![CDATA[服务器]]></category>
		<category><![CDATA[网站开发]]></category>

		<guid isPermaLink="false">http://www.cslog.cn/?p=727</guid>
		<description><![CDATA[先前的开发的Ruby on Rails网站使用的服务程序是Mongrel + N &#8230; <a href="http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>先前的开发的Ruby on Rails网站使用的服务程序是<a title="在ubuntu6.06上安装apache2.2X + mysql + PHP + Ruby on Rails + Mongrel Cluster | 船长日志" href="http://www.cslog.cn/Content/ubuntu606_mysql_apache2_ruby_rails_mongrel_cluster/">Mongrel + Nginx</a>， 现在用了Rails 3， 发现Mongrel对它有兼容问题， 所以要换一个。 虽然现在<a title="Overview — Phusion Passenger™ (a.k.a. mod_rails / mod_rack)" href="http://www.modrails.com/">Phusion Passenger</a>大行其道， 但使用前要重新编译Nginx。 为了避免重新安装nginx，我找到mongrel的替代品<a title="File: README [Unicorn: Rack HTTP server for fast clients and Unix]" href="http://unicorn.bogomips.org/">Unicorn</a>。 没想到unicorn的设置非常方便。 我记录在这里供大家参考：</p>
<p>安装unicorn:<br />
<code><br />
sudo gem install unicorn<br />
</code></p>
<p>创建网站配置文件(myproject是项目名称):<br />
<code><span id="more-727"></span><br />
sudo mkdir /etc/unicorn<br />
cd /etc/unicorn/<br />
sudo nano /etc/unicorn/myproject.conf<br />
</code></p>
<p>内容如下：<br />
<code><br />
RAILS_ROOT=/www/myproject<br />
RAILS_ENV=production<br />
</code></p>
<p>在网站里再创建一个unicorn配置文件<br />
<code><br />
nano /www/myproject/config/unicorn.rb<br />
</code></p>
<p>内容如下：<br />
<code><br />
# Minimal sample configuration file for Unicorn (not Rack) when used<br />
# with daemonization (unicorn -D) started in your working directory.<br />
#<br />
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete<br />
# documentation.<br />
# See also http://unicorn.bogomips.org/examples/unicorn.conf.rb for<br />
# a more verbose configuration using more features.</code></p>
<p><code> </code></p>
<p><code>app_path = "/www/myproject"</code></p>
<p><code> </code></p>
<p><code>listen 8080 # by default Unicorn listens on port 8080<br />
worker_processes 2 # this should be &gt;= nr_cpus<br />
pid "#{app_path}/tmp/pids/unicorn.pid"<br />
stderr_path "#{app_path}/log/unicorn.log"<br />
stdout_path "#{app_path}/log/unicorn.log"<br />
</code></p>
<p>设置unicorn启动脚本：<br />
<code><br />
sudo nano /etc/init.d/unicorn_init<br />
</code><br />
脚本内容：<br />
<code><br />
#!/bin/sh<br />
#<br />
# init.d script for single or multiple unicorn installations. Expects at least one .conf<br />
# file in /etc/unicorn<br />
#<br />
# Modified by jay@gooby.org http://github.com/jaygooby<br />
# based on http://gist.github.com/308216 by http://github.com/mguterl<br />
#<br />
## A sample /etc/unicorn/my_app.conf<br />
##<br />
## RAILS_ENV=production<br />
## RAILS_ROOT=/var/apps/www/my_app/current<br />
#<br />
# This configures a unicorn master for your app at /var/apps/www/my_app/current running in<br />
# production mode. It will read config/unicorn.rb for further set up.<br />
#<br />
# You should ensure different ports or sockets are set in each config/unicorn.rb if<br />
# you are running more than one master concurrently.<br />
#<br />
# If you call this script without any config parameters, it will attempt to run the<br />
# init command for all your unicorn configurations listed in /etc/unicorn/*.conf<br />
#<br />
# /etc/init.d/unicorn start # starts all unicorns<br />
#<br />
# If you specify a particular config, it will only operate on that one<br />
#<br />
# /etc/init.d/unicorn start /etc/unicorn/my_app.conf</code></p>
<p><code> </code></p>
<p><code>set -e</code></p>
<p><code>sig () {<br />
test -s "$PID" &amp;&amp; kill -$1 `cat "$PID"`<br />
}</p>
<p>oldsig () {<br />
test -s "$OLD_PID" &amp;&amp; kill -$1 `cat "$OLD_PID"`<br />
}</p>
<p>cmd () {</p>
<p>case $1 in<br />
start)<br />
sig 0 &amp;&amp; echo &gt;&amp;2 "Already running" &amp;&amp; exit 0<br />
echo "Starting"<br />
$CMD<br />
;;<br />
stop)<br />
sig QUIT &amp;&amp; echo "Stopping" &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Not running"<br />
;;<br />
force-stop)<br />
sig TERM &amp;&amp; echo "Forcing a stop" &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Not running"<br />
;;<br />
restart|reload)<br />
sig USR2 &amp;&amp; sleep 5 &amp;&amp; oldsig QUIT &amp;&amp; echo "Killing old master" `cat $OLD_PID` &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't reload, starting '$CMD' instead"<br />
$CMD<br />
;;<br />
upgrade)<br />
sig USR2 &amp;&amp; echo Upgraded &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't upgrade, starting '$CMD' instead"<br />
$CMD<br />
;;<br />
rotate)<br />
sig USR1 &amp;&amp; echo rotated logs OK &amp;&amp; exit 0<br />
echo &gt;&amp;2 "Couldn't rotate logs" &amp;&amp; exit 1<br />
;;<br />
*)<br />
echo &gt;&amp;2 "Usage: $0 "<br />
exit 1<br />
;;<br />
esac<br />
}</p>
<p>setup () {</p>
<p>echo -n "$RAILS_ROOT: "<br />
cd $RAILS_ROOT || exit 1<br />
export PID=$RAILS_ROOT/tmp/pids/unicorn.pid<br />
export OLD_PID="$PID.oldbin"</p>
<p>CMD="/usr/bin/unicorn_rails -c config/unicorn.rb -E $RAILS_ENV -D"<br />
}</p>
<p>start_stop () {</p>
<p># either run the start/stop/reload/etc command for every config under /etc/unicorn<br />
# or just do it for a specific one</p>
<p># $1 contains the start/stop/etc command<br />
# $2 if it exists, should be the specific config we want to act on<br />
if [ $2 ]; then<br />
. $2<br />
setup<br />
cmd $1<br />
else<br />
for CONFIG in /etc/unicorn/*.conf; do<br />
# import the variables<br />
. $CONFIG<br />
setup</p>
<p># run the start/stop/etc command<br />
cmd $1<br />
done<br />
fi<br />
}</p>
<p></code></p>
<p><code>ARGS="$1 $2"<br />
start_stop $ARGS<br />
</code><br />
注意将里面的/usr/bin/unicorn_rails 换成你系统中unicorn_rails程序的实际路径。</p>
<p>设置unicorn_init文件属性:<br />
<code><br />
sudo chmod 755 /etc/init.d/unicorn_init<br />
</code></p>
<p>启动unicorn:<br />
<code><br />
/etc/init.d/unicorn_init<br />
</code></p>
<p>修改nginx的配置文件，加入unicorn的代理设置：<br />
<code><br />
upstream myproject_mongrel {<br />
server 127.0.0.1:8080 fail_timeout=0;<br />
}<br />
</code><br />
这部分跟使用mongrel的类似的。</p>
<p>这样unicorn的设置就完成了。 刚设置好，感觉unicorn跟mongrel一样， 都是比较吃内存的， 一启动就占了50M. 不知道会不会也像mongrel一样把内存吃爆， 会得话得设置监控软件（如god）看住它。
<div style="margin-top: 15px; font-style: italic">
<p>转载请注明: 转自<a href="http://www.cslog.cn/">船长日志</a>, 本文链接地址: <a href="http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/">http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/unicorn-for-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extreme Programming and Test-Driven Development</title>
		<link>http://www.cslog.cn/Content/extreme-programming-and-test-driven-development/</link>
		<comments>http://www.cslog.cn/Content/extreme-programming-and-test-driven-development/#comments</comments>
		<pubDate>Sun, 06 May 2007 05:49:22 +0000</pubDate>
		<dc:creator>船长</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[softwareengineering]]></category>
		<category><![CDATA[testdrivendevelopment]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Extreme Programming Extreme Programming  &#8230; <a href="http://www.cslog.cn/Content/extreme-programming-and-test-driven-development/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong><font color="#ff6600">Extreme Programming</font></strong><br />
Extreme Programming (or XP) is a <strong><font color="#0000ff">software engineering methodology</font></strong>, the most prominent of several agile software development methodologies.</p>
<p>Extreme Programming Explained describes Extreme Programming as being:<br />
&nbsp;&nbsp;&nbsp; * An attempt to reconcile <strong>humanity</strong> and <strong>productivity</strong><br />
&nbsp;&nbsp;&nbsp; * A mechanism for social change<br />
&nbsp;&nbsp;&nbsp; * A path to improvement<br />
&nbsp;&nbsp;&nbsp; * A style of <strong>development</strong><br />
&nbsp;&nbsp;&nbsp; * A software development discipline</p>
<p><strong><br />
</strong><strong><font color="#ff6600">Test-Driven Development</font></strong><br />
<strong>The goal of TDD is to write clean code that works. </strong></p>
<p><strong><font color="#ff6600">What is Test-Driven Development?</font></strong><br />
Test-Driven Development (TDD) is <strong><font color="#0000ff">a software development technique</font></strong> that involves repeatedly first writing a test case and then implementing only the code necessary to pass the test. Test-driven development is a method of designing software, not merely a method of testing.</p>
<p>In addition to normal &ldquo;did it pass?&rdquo; testing, you can go the opposite route. By testing your application where the weak points are, you can fix it before it ever becomes an issue.</p>
<p><strong><font color="#ff6600">Test-Driven Development Cycle</font></strong><br />
<font color="#0000ff"><strong>1. Add a test</strong></font><br />
In order to write a test, the developer <strong><font color="#ff0000">must</font></strong> understand the specification and the requirements of the feature clearly. <br />
<strong><font color="#0000ff">2. Run all tests and see the new one fail</font></strong><br />
testing the tests<br />
<strong><font color="#0000ff">3. Write some code</font></strong><br />
It is important that the code written is only designed to pass the test; no further (and therefore untested) functionality should be predicted and &#8216;allowed for&#8217; at any stage.</p>
<p><font color="#808080"><em><strong>KISS</strong><br />
Keep It Simple, Stupid.<br />
Everything should be made as simple as possible, but no simpler.<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &#8211;Albert Einstein</em></p>
<p><em><strong>You Ain&#8217;t Gonna Need It</strong><br />
&#8216;You Ain&#8217;t Gonna Need It&#8217;(YAGNI), is a reminder for programmers that one should never add functionality until it is necessary. </em></font></p>
<p><strong><font color="#0000ff">4. Run the automated tests and see them succeed<br />
5. Refactor code</font></strong></p>
<p>
<font color="#808080"><strong>Refactoring</strong><br />
A code refactoring is any change to a computer program which improves its readability or simplifies its structure without changing its results.<br />
List of refactorings</p>
<p>&nbsp;&nbsp;&nbsp; * Encapsulate Field(e.g. providing methods that can be used to read/write to/from the field rather than accessing the field directly.) <br />
&nbsp;&nbsp;&nbsp; * Extract Method (to turn part of a larger method into a new method. By breaking down code in smaller pieces, it is more easily understandable. This is also applicable to functions)<br />
&nbsp;&nbsp;&nbsp; * Generalize Type (to making more general or more abstract some subset of the traits of a specific type. An example of generalizing a type would be moving a method from a child to a parent class for common use by all the parent class&#8217; children, not just the original child.)<br />
&nbsp;&nbsp;&nbsp; * Pull Up (moving a method from a Subclass into a Superclass. )<br />
&nbsp;&nbsp;&nbsp; * Push Down (moving a method from a SuperClass into a SubClass.)<br />
&nbsp;&nbsp;&nbsp; * Rename Method (changing the name of a method into a new one that better reveals its purpose).</font></p>
<p>The cycle is then repeated, starting with another new test to push forward the functionality. </p>
<p>&quot;Test-Driven Development Mantra&quot; is known as <font color="#ff0000">red</font>/<font color="#00ff00">green</font>/refactor where red means fail and green is pass.</p>
<p>
<strong><font color="#ff6600">Benefits</font></strong><br />
By focusing on the test cases first, one must imagine how the functionality will be used by clients (in this case, the test cases). Therefore, the programmer is <strong><font color="#0000ff">only concerned with the interface and not the implementation.</font></strong><br />
It allows a programmer to <strong><font color="#0000ff">focus on the task at hand</font></strong> as the first goal is to make the test pass. <br />
Ensuring that all written code is covered by a test. </p>
<p>
<strong><font color="#ff6600">Limitations</font></strong><br />
A test-driven development is only as good as its tests. </p>
<p>Reference<br />
<a href="http://en.wikipedia.org/wiki/Test-driven_development">http://en.wikipedia.org/wiki/Test-driven_development</a><br />
<a href="http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It">http://en.wikipedia.org/wiki/You_Ain%27t_Gonna_Need_It</a><br />
<a href="http://en.wikipedia.org/wiki/Refactoring">http://en.wikipedia.org/wiki/Refactoring</a></p>
<p>Related Resources<br />
<a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html">Test::Unit &#8211; Ruby Unit Testing Framework</a><br />
<a href="http://manuals.rubyonrails.com/read/book/5">A Guide to Testing the Rails<br />
</a><a href="http://blog.zenspider.com/archives/2006/04/test_driven_des.html">Test Driven Design for Ruby and Rails<br />
</a><a href="http://nubyonrails.com/articles/2006/08/24/ruby-rails-test-rails-cheat-sheet">Ruby, Rails, Test::Rails Cheat Sheet<br />
</a>
<div style="margin-top: 15px; font-style: italic">
<p>转载请注明: 转自<a href="http://www.cslog.cn/">船长日志</a>, 本文链接地址: <a href="http://www.cslog.cn/Content/extreme-programming-and-test-driven-development/">http://www.cslog.cn/Content/extreme-programming-and-test-driven-development/</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.cslog.cn/Content/extreme-programming-and-test-driven-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
