<?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>Weixuhong.com</title>
	<atom:link href="http://weixuhong.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://weixuhong.com</link>
	<description>韦旭红的个人网站－－记录心路历程...</description>
	<lastBuildDate>Tue, 18 Oct 2011 13:01:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>关于backbone _.bindAll</title>
		<link>http://weixuhong.com/%e6%8a%80%e6%9c%af%e6%84%9f%e6%83%b3/2011/10/13/%e5%85%b3%e4%ba%8ebackbone-_-bindall/</link>
		<comments>http://weixuhong.com/%e6%8a%80%e6%9c%af%e6%84%9f%e6%83%b3/2011/10/13/%e5%85%b3%e4%ba%8ebackbone-_-bindall/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 05:39:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[技术感想]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=563</guid>
		<description><![CDATA[
			_.bindAll(this, 'render');
			this.model.bind('change', this.render);

以上这两行代码主要为了当model改变时， view执行render， 那_.bindAll有什么用呢？
看这里：http://stackoverflow.com/questions/6079055/why-do-bindall-in-backbone-js-views
其中有一段是这样的：

	Without _.bindAll( this, 'render' ) when model changes this in render will be pointing to the model, not to the view, so we won't have neither this.el nor this.$ or any other view's properties available.

当model被change时， this指向model, 但是我们要执行render, 那么就需要_.bindAll(this, &#8216;render&#8217;)， 使model也有这个render的方法？
请达人解答?
*
新版本这样就可以
this.model.bind(&#8217;change&#8217;, this.render, this);













]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="javasript" style="font-family:monospace;">			_.bindAll(this, 'render');
			this.model.bind('change', this.render);</pre></div></div>

<p>以上这两行代码主要为了当model改变时， view执行render， 那_.bindAll有什么用呢？</p>
<p>看这里：http://stackoverflow.com/questions/6079055/why-do-bindall-in-backbone-js-views</p>
<p>其中有一段是这样的：</p>
<pre>
	Without _.bindAll( this, 'render' ) when model changes this in render will be pointing to the model, not to the view, so we won't have neither this.el nor this.$ or any other view's properties available.
</pre>
<p>当model被change时， this指向model, 但是我们要执行render, 那么就需要_.bindAll(this, &#8216;render&#8217;)， 使model也有这个render的方法？</p>
<p>请达人解答?</p>
<p>*<br />
新版本这样就可以</p>
<p>this.model.bind(&#8217;change&#8217;, this.render, this);</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://weixuhong.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-14-at-1.55.50-PM.png" alt="Screen Shot 2011-10-14 at 1.55.50 PM.png" border="0" width="406" height="567" /></p>
<p></p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://weixuhong.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-14-at-2.06.54-PM.png" alt="Screen Shot 2011-10-14 at 2.06.54 PM.png" border="0" width="600" height="352" /></p>
<p></p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://weixuhong.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-14-at-2.18.03-PM.png" alt="Screen Shot 2011-10-14 at 2.18.03 PM.png" border="0" width="417" height="590" /></p>
<p></p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://weixuhong.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-14-at-3.31.51-PM.png" alt="Screen Shot 2011-10-14 at 3.31.51 PM.png" border="0" width="600" height="432" /></p>
<p></p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://weixuhong.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-14-at-3.33.11-PM.png" alt="Screen Shot 2011-10-14 at 3.33.11 PM.png" border="0" width="600" height="380" /></p>
<p></p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://weixuhong.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-17-at-5.20.27-PM.png" alt="Screen Shot 2011-10-17 at 5.20.27 PM.png" border="0" width="600" height="332" /></p>
<p></p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://weixuhong.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-18-at-3.37.23-PM.png" alt="Screen Shot 2011-10-18 at 3.37.23 PM.png" border="0" width="600" height="378" /></p>
]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/%e6%8a%80%e6%9c%af%e6%84%9f%e6%83%b3/2011/10/13/%e5%85%b3%e4%ba%8ebackbone-_-bindall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>APIdock in Textmate</title>
		<link>http://weixuhong.com/%e6%8a%80%e6%9c%af%e6%84%9f%e6%83%b3/2011/10/08/apidock-in-textmate/</link>
		<comments>http://weixuhong.com/%e6%8a%80%e6%9c%af%e6%84%9f%e6%83%b3/2011/10/08/apidock-in-textmate/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 04:46:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[技术感想]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=561</guid>
		<description><![CDATA[
% mkdir -p ~/Library/Application\ Support/Textmate/Bundles
% cd ~/Library/Application\ Support/Textmate/Bundles
% git clone git://github.com/lautis/ruby-on-rails-tmbundle.git &#34;Ruby on Rails.tmbundle&#34;
% git clone git://github.com/lautis/ruby-tmbundle.git &#34;Ruby.tmbundle&#34;
% osascript -e 'tell app &#34;TextMate&#34; to reload bundles'

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">%</span> mkdir <span style="color: #339933;">-</span>p ~<span style="color: #339933;">/</span>Library<span style="color: #339933;">/</span>Application\ Support<span style="color: #339933;">/</span>Textmate<span style="color: #339933;">/</span>Bundles
<span style="color: #339933;">%</span> cd ~<span style="color: #339933;">/</span>Library<span style="color: #339933;">/</span>Application\ Support<span style="color: #339933;">/</span>Textmate<span style="color: #339933;">/</span>Bundles
<span style="color: #339933;">%</span> git clone git<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//github.com/lautis/ruby-on-rails-tmbundle.git &quot;Ruby on Rails.tmbundle&quot;</span>
<span style="color: #339933;">%</span> git clone git<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//github.com/lautis/ruby-tmbundle.git &quot;Ruby.tmbundle&quot;</span>
<span style="color: #339933;">%</span> osascript <span style="color: #339933;">-</span>e <span style="color: #ff0000;">'tell app &quot;TextMate&quot; to reload bundles'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/%e6%8a%80%e6%9c%af%e6%84%9f%e6%83%b3/2011/10/08/apidock-in-textmate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>安装passenger for rails3</title>
		<link>http://weixuhong.com/rubyruby-on-rails/2011/09/07/%e5%ae%89%e8%a3%85passenger-for-rails3/</link>
		<comments>http://weixuhong.com/rubyruby-on-rails/2011/09/07/%e5%ae%89%e8%a3%85passenger-for-rails3/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 05:32:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby/Ruby on Rails]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=557</guid>
		<description><![CDATA[
&#160;
gem install passenger


yum install apr-devel
yum install apr-util-devel
yum install httpd-devel


passenger-install-apache2-module

复杂以下文件到httpd.conf

   LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.2-p290-module/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p290-module/gems/passenger-3.0.9
   PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.2-p290-module/ruby


#For PAIFAN 后台
&#60;VirtualHost *:80&#62;
 ServerName padmin.qdigit.cn
 RailsEnv production
 #RailsEnv development 
 DocumentRoot /var/www/html/admin.insta/public
 ErrorLog /var/www/html/admin.insta/log/redmine.error.log
  &#60;Directory /var/www/html/admin.insta/public&#62;
  AllowOverride all
  #Options -MultiViews           [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
gem install passenger</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">yum install apr<span style="color: #339933;">-</span>devel
yum install apr<span style="color: #339933;">-</span>util<span style="color: #339933;">-</span>devel
yum install httpd<span style="color: #339933;">-</span>devel</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">passenger<span style="color: #339933;">-</span>install<span style="color: #339933;">-</span>apache2<span style="color: #339933;">-</span>module</pre></div></div>

<p>复杂以下文件到httpd.conf</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">   LoadModule passenger_module <span style="color: #339933;">/</span>usr<span style="color: #339933;">/</span>local<span style="color: #339933;">/</span>rvm<span style="color: #339933;">/</span>gems<span style="color: #339933;">/</span>ruby<span style="color: #339933;">-</span>1.9.2<span style="color: #339933;">-</span>p290<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>gems<span style="color: #339933;">/</span>passenger<span style="color: #339933;">-</span>3.0.9<span style="color: #339933;">/</span>ext<span style="color: #339933;">/</span>apache2<span style="color: #339933;">/</span>mod_passenger.<span style="color: #202020;">so</span>
   PassengerRoot <span style="color: #339933;">/</span>usr<span style="color: #339933;">/</span>local<span style="color: #339933;">/</span>rvm<span style="color: #339933;">/</span>gems<span style="color: #339933;">/</span>ruby<span style="color: #339933;">-</span>1.9.2<span style="color: #339933;">-</span>p290<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>gems<span style="color: #339933;">/</span>passenger<span style="color: #339933;">-</span>3.0.9
   PassengerRuby <span style="color: #339933;">/</span>usr<span style="color: #339933;">/</span>local<span style="color: #339933;">/</span>rvm<span style="color: #339933;">/</span>wrappers<span style="color: #339933;">/</span>ruby<span style="color: #339933;">-</span>1.9.2<span style="color: #339933;">-</span>p290<span style="color: #339933;">-</span>module<span style="color: #339933;">/</span>ruby</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#For PAIFAN 后台</span>
<span style="color: #339933;">&lt;</span>VirtualHost <span style="color: #339933;">*:</span><span style="color: #0000dd;">80</span><span style="color: #339933;">&gt;</span>
 ServerName padmin.<span style="color: #202020;">qdigit</span>.<span style="color: #202020;">cn</span>
 RailsEnv production
 <span style="color: #339933;">#RailsEnv development </span>
 DocumentRoot <span style="color: #339933;">/</span>var<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>html<span style="color: #339933;">/</span>admin.<span style="color: #202020;">insta</span><span style="color: #339933;">/</span>public
 ErrorLog <span style="color: #339933;">/</span>var<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>html<span style="color: #339933;">/</span>admin.<span style="color: #202020;">insta</span><span style="color: #339933;">/</span>log<span style="color: #339933;">/</span>redmine.<span style="color: #202020;">error</span>.<span style="color: #202020;">log</span>
  <span style="color: #339933;">&lt;</span>Directory <span style="color: #339933;">/</span>var<span style="color: #339933;">/</span>www<span style="color: #339933;">/</span>html<span style="color: #339933;">/</span>admin.<span style="color: #202020;">insta</span><span style="color: #339933;">/</span>public<span style="color: #339933;">&gt;</span>
  AllowOverride all
  <span style="color: #339933;">#Options -MultiViews           </span>
  Options Indexes <span style="color: #339933;">-</span>MultiViews
 <span style="color: #339933;">&lt;/</span>Directory<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>VirtualHost<span style="color: #339933;">&gt;</span></pre></div></div>

<p>参考: http://www.modrails.com/install.html</p>
]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/rubyruby-on-rails/2011/09/07/%e5%ae%89%e8%a3%85passenger-for-rails3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如果使用ruby gem redis查看redis的keys</title>
		<link>http://weixuhong.com/rubyruby-on-rails/2011/08/04/%e5%a6%82%e6%9e%9c%e4%bd%bf%e7%94%a8ruby-gem-redis%e6%9f%a5%e7%9c%8bredis%e7%9a%84keys/</link>
		<comments>http://weixuhong.com/rubyruby-on-rails/2011/08/04/%e5%a6%82%e6%9e%9c%e4%bd%bf%e7%94%a8ruby-gem-redis%e6%9f%a5%e7%9c%8bredis%e7%9a%84keys/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 05:18:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby/Ruby on Rails]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=553</guid>
		<description><![CDATA[
&#160;
irb&#40;main&#41;:002:0&#62; require 'rubygems'
=&#62; true
irb&#40;main&#41;:003:0&#62; require 'redis'
=&#62; true
irb&#40;main&#41;:004:0&#62; r = Redis.new
=&#62; #&#60;Redis:0x8605b64 @sock=#&#60;TCPSocket:0x8605ab0&#62;, @timeout=5, @port=6379, @db=0, @host=&#34;127.0.0.1&#34;&#62;
irb&#40;main&#41;:005:0&#62; r.keys&#40;'*'&#41;
&#160;
列出某个的key的值：
&#160;
r.sort&#40;&#34;Listen:1&#34;&#41;

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:002:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:003:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'redis'</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:004:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> r = Redis.<span style="color:#9900CC;">new</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#008000; font-style:italic;">#&lt;Redis:0x8605b64 @sock=#&lt;TCPSocket:0x8605ab0&gt;, @timeout=5, @port=6379, @db=0, @host=&quot;127.0.0.1&quot;&gt;</span>
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:005:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> r.<span style="color:#9900CC;">keys</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'*'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
列出某个的key的值：
&nbsp;
r.<span style="color:#9900CC;">sort</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Listen:1&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/rubyruby-on-rails/2011/08/04/%e5%a6%82%e6%9e%9c%e4%bd%bf%e7%94%a8ruby-gem-redis%e6%9f%a5%e7%9c%8bredis%e7%9a%84keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>rails 3.1 Mountable Engines 使用方法</title>
		<link>http://weixuhong.com/rubyruby-on-rails/2011/08/01/rails-3-1-mountable-engines-%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95/</link>
		<comments>http://weixuhong.com/rubyruby-on-rails/2011/08/01/rails-3-1-mountable-engines-%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 02:45:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby/Ruby on Rails]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=551</guid>
		<description><![CDATA[在了解 Moutable之前， 先看这个视频：
http://railscasts.com/episodes/277-mountable-engines
了解Mountable Engines与Full Engines的区别， 看这篇文章:
http://stackoverflow.com/questions/6118905/rails-3-1-engine-vs-mountable-app
当我们使用：

rails plugin new uhoh --mountable

我们可以把这个创建好的plugin变成一个gem来使用。
比如我们可以先创建一个rails app

 rails new with_engine -T -O -J

编辑Gemfile, 添加以下一行:

&#160;
 gem 'uhoh', :path =&#62; '/Users/weston/Downloads/277-mountable-engines/uhoh-after/' #刚才创建的mountable 路径

执行

&#160;
bundle install 
&#160;
vim config/routs.rb

添加以下一行:

   mount Uhoh::Engine =&#62; &#34;/uhoh&#34;, :as =&#62; &#34;uhoh_engine&#34;

这样我们就可以使用这个engines了&#8230;
]]></description>
			<content:encoded><![CDATA[<p>在了解 Moutable之前， 先看这个视频：<br />
http://railscasts.com/episodes/277-mountable-engines</p>
<p>了解Mountable Engines与Full Engines的区别， 看这篇文章:<br />
http://stackoverflow.com/questions/6118905/rails-3-1-engine-vs-mountable-app</p>
<p>当我们使用：</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">rails plugin new uhoh <span style="color:#006600; font-weight:bold;">--</span>mountable</pre></div></div>

<p>我们可以把这个创建好的plugin变成一个gem来使用。</p>
<p>比如我们可以先创建一个rails app</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> rails new with_engine <span style="color:#006600; font-weight:bold;">-</span>T <span style="color:#006600; font-weight:bold;">-</span>O <span style="color:#006600; font-weight:bold;">-</span>J</pre></div></div>

<p>编辑Gemfile, 添加以下一行:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
 gem <span style="color:#996600;">'uhoh'</span>, <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'/Users/weston/Downloads/277-mountable-engines/uhoh-after/'</span> <span style="color:#008000; font-style:italic;">#刚才创建的mountable 路径</span></pre></div></div>

<p>执行</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
bundle install 
&nbsp;
vim config<span style="color:#006600; font-weight:bold;">/</span>routs.<span style="color:#9900CC;">rb</span></pre></div></div>

<p>添加以下一行:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">   mount <span style="color:#6666ff; font-weight:bold;">Uhoh::Engine</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/uhoh&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:as</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;uhoh_engine&quot;</span></pre></div></div>

<p>这样我们就可以使用这个engines了&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/rubyruby-on-rails/2011/08/01/rails-3-1-mountable-engines-%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于Rails使用Callback和Observer的区别</title>
		<link>http://weixuhong.com/rubyruby-on-rails/2011/07/27/%e5%85%b3%e4%ba%8erails%e4%bd%bf%e7%94%a8callback%e5%92%8cobserver%e7%9a%84%e5%8c%ba%e5%88%ab/</link>
		<comments>http://weixuhong.com/rubyruby-on-rails/2011/07/27/%e5%85%b3%e4%ba%8erails%e4%bd%bf%e7%94%a8callback%e5%92%8cobserver%e7%9a%84%e5%8c%ba%e5%88%ab/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 08:11:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby/Ruby on Rails]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=547</guid>
		<description><![CDATA[可以参考：
http://stackoverflow.com/questions/1531514/observers-vs-callbacks
其中有一段是这样的：

&#160;
class Model &#60; ActiveRecord::Base
  before_update :disallow_bob
&#160;
  def disallow_bob
  return false if model.name == &#34;bob&#34;
  end
end
&#160;
class ModelObserver &#60; ActiveRecord::Observer
  def before_update&#40;model&#41;
    return false if model.name == &#34;mary&#34;
  end
end
&#160;
m = Model.create&#40;:name =&#62; &#34;whatever&#34;&#41;
&#160;
m.update_attributes&#40;:name =&#62; &#34;bob&#34;&#41;
=&#62; false -- name will still be &#34;whatever&#34; in database
&#160;
m.update_attributes&#40;:name =&#62; &#34;mary&#34;&#41;
=&#62; true -- [...]]]></description>
			<content:encoded><![CDATA[<p>可以参考：<br />
http://stackoverflow.com/questions/1531514/observers-vs-callbacks</p>
<p>其中有一段是这样的：</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> Model <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  before_update <span style="color:#ff3333; font-weight:bold;">:disallow_bob</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> disallow_bob
  <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#9966CC; font-weight:bold;">if</span> model.<span style="color:#9900CC;">name</span> == <span style="color:#996600;">&quot;bob&quot;</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;">class</span> ModelObserver <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Observer</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> before_update<span style="color:#006600; font-weight:bold;">&#40;</span>model<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#9966CC; font-weight:bold;">if</span> model.<span style="color:#9900CC;">name</span> == <span style="color:#996600;">&quot;mary&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
m = Model.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;whatever&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
m.<span style="color:#9900CC;">update_attributes</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;bob&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span> <span style="color:#006600; font-weight:bold;">--</span> name will still be <span style="color:#996600;">&quot;whatever&quot;</span> <span style="color:#9966CC; font-weight:bold;">in</span> database
&nbsp;
m.<span style="color:#9900CC;">update_attributes</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;mary&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span> <span style="color:#006600; font-weight:bold;">--</span> name will be <span style="color:#996600;">&quot;mary&quot;</span> <span style="color:#9966CC; font-weight:bold;">in</span> database</pre></div></div>

<p>Observers may only observe, they may not intervene.</p>
]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/rubyruby-on-rails/2011/07/27/%e5%85%b3%e4%ba%8erails%e4%bd%bf%e7%94%a8callback%e5%92%8cobserver%e7%9a%84%e5%8c%ba%e5%88%ab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 3, RSpec, Cucumber, jQuery, Devise, Mongoid, and Compass(转)</title>
		<link>http://weixuhong.com/rubyruby-on-rails/2011/07/19/rails-3-rspec-cucumber-jquery-devise-mongoid-and-compass%e8%bd%ac/</link>
		<comments>http://weixuhong.com/rubyruby-on-rails/2011/07/19/rails-3-rspec-cucumber-jquery-devise-mongoid-and-compass%e8%bd%ac/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 06:17:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby/Ruby on Rails]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=545</guid>
		<description><![CDATA[来源:http://jimdrannbauer.com/2011/01/29/rails-3-rspec-cucumber-jquery-devise-mongoid-and-compass/
Want to build a Rails 3 app with this stuff?
Git
RSpec
Cucumber w/ Capybara
Mongoid
Devise
CanCan
jQuery
Compass
Blueprintcss
Haml
Sass
Capistrano
Passenger
Factory Girl
Shoulda
metric_fu
Here’s how.
Just A Checklist
This article is mostly written for myself so I don’t have to remember where I found all of the information. There’s nothing particularly difficult about anything here. I just like the idea of having it all in one place. I [...]]]></description>
			<content:encoded><![CDATA[<p>来源:http://jimdrannbauer.com/2011/01/29/rails-3-rspec-cucumber-jquery-devise-mongoid-and-compass/</p>
<p>Want to build a Rails 3 app with this stuff?</p>
<p>Git<br />
RSpec<br />
Cucumber w/ Capybara<br />
Mongoid<br />
Devise<br />
CanCan<br />
jQuery<br />
Compass<br />
Blueprintcss<br />
Haml<br />
Sass<br />
Capistrano<br />
Passenger<br />
Factory Girl<br />
Shoulda<br />
metric_fu<br />
Here’s how.</p>
<p>Just A Checklist</p>
<p>This article is mostly written for myself so I don’t have to remember where I found all of the information. There’s nothing particularly difficult about anything here. I just like the idea of having it all in one place. I figured it might be helpful to others, so… uh… here it is.</p>
<p>Having said that, this is not a tutorial. I don’t explain how to do Behavior Driven Development, how to use CanCan, or why to use any of this stuff. It’s just a checklist… a detailed checklist. It would probably make a good Rails Template.</p>
<p>Prerequisites</p>
<p>The installation of MongoDB and Git are beyond the scope…</p>
<p>Initialize the app</p>
<p>In your shell:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">mkdir awesome<span style="color: #339933;">-</span>app
cd awesome<span style="color: #339933;">-</span>app
git init
rails new . <span style="color: #339933;">-</span>T <span style="color: #339933;">-</span>J <span style="color: #339933;">-</span>O</pre></div></div>

<p>Create the empty directory first so that you can init an empty git repo. The -T option excludes the Test/Unit files so that we can use RSpec instead. The -J option excludes the prototype.js files so that we can use jQuery instead. The -O option excludes ActiveRecord (O is for ORM) so that we can use Mongoid instead.</p>
<p>Commit it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
git add .
<span style="color: #202020;">git</span> commit <span style="color: #339933;">-</span>m <span style="color: #ff0000;">&quot;initial commit&quot;</span>
Bundle the Gems</pre></div></div>

<p>Here’s the first place you need to modify files. In Gemfile:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">source <span style="color:#996600;">'http://rubygems.org'</span>
gem <span style="color:#996600;">'rails'</span>,    <span style="color:#996600;">'3.0.3'</span>
gem <span style="color:#996600;">'mongoid'</span>,  <span style="color:#996600;">'2.0.0.rc.6'</span>
gem <span style="color:#996600;">'bson_ext'</span>, <span style="color:#996600;">'~&gt; 1.2'</span>
gem <span style="color:#996600;">'devise'</span>
gem <span style="color:#996600;">'cancan'</span>
gem <span style="color:#996600;">'jquery-rails'</span>
gem <span style="color:#996600;">'passenger'</span>
gem <span style="color:#996600;">'capistrano'</span>
gem <span style="color:#996600;">&quot;compass&quot;</span>, <span style="color:#996600;">&quot;&gt;= 0.10.6&quot;</span>
gem <span style="color:#996600;">'haml'</span>
group <span style="color:#ff3333; font-weight:bold;">:development</span>, <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'capybara'</span>
  gem <span style="color:#996600;">'cucumber'</span>
  gem <span style="color:#996600;">'cucumber-rails'</span>
  gem <span style="color:#996600;">'database_cleaner'</span>
  gem <span style="color:#996600;">'rspec'</span>
  gem <span style="color:#996600;">'rspec-rails'</span>
  gem <span style="color:#996600;">'shoulda'</span>
  gem <span style="color:#996600;">'factory_girl_rails'</span>
  gem <span style="color:#996600;">'autotest'</span>
  gem <span style="color:#996600;">'launchy'</span>
  gem <span style="color:#996600;">'faker'</span>
  gem <span style="color:#996600;">'ruby-debug19'</span>
  gem <span style="color:#996600;">'haml-rails'</span>
  gem <span style="color:#996600;">'metric_fu'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Then, back in your shell:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
bundle install</pre></div></div>

<p>Commit it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
git add .
<span style="color: #202020;">git</span> commit <span style="color: #339933;">-</span>m <span style="color: #ff0000;">&quot;Added Gems&quot;</span>
Mongoid</pre></div></div>

<p>Mongoid is an ORM for MongoDB. I’ll assume you have it installed already. Dig it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
<span style="color: #339933;"># Ignore this message if you see it since you're</span>
<span style="color: #339933;"># running the command it's asking for right now:</span>
&nbsp;
<span style="color: #339933;"># Mongoid config not found. Create a config file at: config/mongoid.yml</span>
<span style="color: #339933;"># to generate one run: rails generate mongoid:config</span>
rails g mongoid<span style="color: #339933;">:</span>config</pre></div></div>

<p>After running the mongoid generator, your app is configured to use Mongoid instead of ActiveRecord. When you generate a model, Rails will generate a Mongoid Document.</p>
<p>Let’s edit some files and get it set up.</p>
<p>In config/mongoid.yml:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
defaults<span style="color: #339933;">:</span> <span style="color: #339933;">&amp;</span>defaults
  host<span style="color: #339933;">:</span> localhost
  <span style="color: #339933;"># mongoid defaults for configurable settings</span>
  autocreate_indexes<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">false</span>
  allow_dynamic_fields<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">true</span>
  include_root_in_json<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">false</span>
  parameterize_keys<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">true</span>
  persist_in_safe_mode<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">false</span>
  raise_not_found_error<span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">true</span>
  reconnect_time<span style="color: #339933;">:</span> <span style="color: #0000dd;">3</span>
development<span style="color: #339933;">:</span>
  <span style="color: #339933;">&lt;&lt;:</span> <span style="color: #339933;">*</span>defaults
  database<span style="color: #339933;">:</span> awesome_app_development
test<span style="color: #339933;">:</span> <span style="color: #339933;">&amp;</span>TEST
  <span style="color: #339933;">&lt;&lt;:</span> <span style="color: #339933;">*</span>defaults
  database<span style="color: #339933;">:</span> awesome_app_test
cucumber<span style="color: #339933;">:</span>
  <span style="color: #339933;">&lt;&lt;:</span> <span style="color: #339933;">*</span>TEST
<span style="color: #339933;"># set these environment variables on your prod server</span>
production<span style="color: #339933;">:</span>
  host<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;%=</span> ENV<span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'MONGOID_HOST'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">%&gt;</span>
  port<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;%=</span> ENV<span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'MONGOID_PORT'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">%&gt;</span>
  username<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;%=</span> ENV<span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'MONGOID_USERNAME'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">%&gt;</span>
  password<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;%=</span> ENV<span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'MONGOID_PASSWORD'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">%&gt;</span>
  database<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;%=</span> ENV<span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'MONGOID_DATABASE'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">%&gt;</span></pre></div></div>

<p>There are 2 things to notice here. First, the configurable settings can be excluded. Even though Mongoid will default to the above options, leave them so that you don’t have to look at the documentation. Second, we added an environment for Cucumber which just points back to the test environment.</p>
<p>Commit it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
git add .
<span style="color: #202020;">git</span> commit <span style="color: #339933;">-</span>m <span style="color: #ff0000;">&quot;Added Mongoid&quot;</span>
RSpec</pre></div></div>

<p>Now, we use the rails generator to install RSpec. Shell:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
rails g rspec<span style="color: #339933;">:</span>install
Next<span style="color: #339933;">,</span> in spec<span style="color: #339933;">/</span>spec_helper.<span style="color: #202020;">rb</span><span style="color: #339933;">:</span>
&nbsp;
RSpec.<span style="color: #202020;">configure</span> <span style="color: #b1b100;">do</span> <span style="color: #339933;">|</span>config<span style="color: #339933;">|</span>
  config.<span style="color: #202020;">mock_with</span> <span style="color: #339933;">:</span>rspec
&nbsp;
  require <span style="color: #ff0000;">'database_cleaner'</span>
&nbsp;
  config.<span style="color: #202020;">before</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">:</span>suite<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">do</span>
    DatabaseCleaner.<span style="color: #202020;">strategy</span> <span style="color: #339933;">=</span> <span style="color: #339933;">:</span>truncation
    DatabaseCleaner.<span style="color: #202020;">orm</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;mongoid&quot;</span>
  end
&nbsp;
  config.<span style="color: #202020;">before</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">:</span>each<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">do</span>
    DatabaseCleaner.<span style="color: #202020;">clean</span>
  end
end</pre></div></div>

<p>This is all you need in your RSpec configuration to use it with Mongoid. MongoDB doesn’t do transactions so we need to truncate the database between tests instead of rolling back. DatabaseCleaner helps with that.</p>
<p>Commit it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
git add .
<span style="color: #202020;">git</span> commit <span style="color: #339933;">-</span>m <span style="color: #ff0000;">&quot;Added RSpec&quot;</span></pre></div></div>

<p>Cucumber</p>
<p>Next, we use the rails generator again to install Cucumber. Shell:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
rails g cucumber<span style="color: #339933;">:</span>install <span style="color: #339933;">--</span>capybara <span style="color: #339933;">--</span>rspec <span style="color: #339933;">--</span>skip<span style="color: #339933;">-</span>database</pre></div></div>

<p>The –capybara option sets up Capybara instead of Webrat. The –rspec option enables RSpec matchers for your step definitions.</p>
<p>The Cucumber generator will bark at you about a missing database.yml file without the –skip-database option because we skipped the ORM when we created the app.</p>
<p>Like RSpec, some configuration is necessary to make Cucumber play nice with Mongoid. Add this file, features/support/database_cleaner.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
require <span style="color: #ff0000;">'database_cleaner'</span>
DatabaseCleaner.<span style="color: #202020;">strategy</span> <span style="color: #339933;">=</span> <span style="color: #339933;">:</span>truncation
DatabaseCleaner.<span style="color: #202020;">orm</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;mongoid&quot;</span>
Before <span style="color: #009900;">&#123;</span> DatabaseCleaner.<span style="color: #202020;">clean</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>This does the same thing for Cucumber that it does for RSpec: truncates your data between scenarios.</p>
<p>Commit it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
git add .
<span style="color: #202020;">git</span> commit <span style="color: #339933;">-</span>m <span style="color: #ff0000;">&quot;Added Cucumber&quot;</span></pre></div></div>

<p>Devise</p>
<p>Devise is used for authentication.</p>
<p>Shell it:</p>
<p>rails g devise:install<br />
Devise needs a few things in place so that it can provide it’s functionality and it’ll let you know it when the installation is done:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">===============================================================================</span>
&nbsp;
Some setup you must <span style="color: #b1b100;">do</span> manually <span style="color: #b1b100;">if</span> you haven<span style="color: #ff0000;">'t yet:
&nbsp;
  1. Setup default url options for your specific environment. Here is an
     example of development environment:
&nbsp;
       config.action_mailer.default_url_options = { :host =&gt; '</span>localhost<span style="color: #339933;">:</span><span style="color: #0000dd;">3000</span><span style="color: #ff0000;">' }
&nbsp;
     This is a required Rails configuration. In production it must be the
     actual host of your application
&nbsp;
  2. Ensure you have defined root_url to *something* in your config/routes.rb.
     For example:
&nbsp;
       root :to =&gt; &quot;home#index&quot;
&nbsp;
  3. Ensure you have flash messages in app/views/layouts/application.html.erb.
     For example:
&nbsp;
       &lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;
       &lt;p class=&quot;alert&quot;&gt;&lt;%= alert %&gt;&lt;/p&gt;
&nbsp;
===============================================================================</span></pre></div></div>

<p>For now, all you need to do are steps 1 and 2 above. We’ll handle step 3 when we get into the Haml/Sass/Compass stuff later.</p>
<p>In config/environments/development.rb, add this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">config.<span style="color: #202020;">action_mailer</span>.<span style="color: #202020;">default_url_options</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #339933;">:</span>host <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'localhost:3000'</span> <span style="color: #009900;">&#125;</span></pre></div></div>

<p>In config/routes.rb, add this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
root <span style="color: #339933;">:</span>to <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;home#index&quot;</span>
<span style="color: #339933;">&lt;</span>pre<span style="color: #339933;">&gt;</span>
&nbsp;
Finally<span style="color: #339933;">,</span> Devise needs a model to hold login credentials. <span style="color: #202020;">Let</span>’s call it User. <span style="color: #202020;">In</span> the shell<span style="color: #339933;">:</span>
<span style="color: #339933;">&lt;</span>pre lang<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;c&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
rails g mongoid<span style="color: #339933;">:</span>devise User</pre></div></div>

<p>Take a look in app/models/user.rb. Notice that it generated a Mongoid Document.</p>
<p>Finish up by adding this to routes.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
devise_for <span style="color: #339933;">:</span>users
Commit it<span style="color: #339933;">:</span>
&nbsp;
git add .
<span style="color: #202020;">git</span> commit <span style="color: #339933;">-</span>m <span style="color: #ff0000;">&quot;Added Devise&quot;</span></pre></div></div>

<p>CanCan</p>
<p>CanCan does role-based user authorization.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
rails g cancan<span style="color: #339933;">:</span>ability
That’s it.</pre></div></div>

<p>Commit it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
git add .
<span style="color: #202020;">git</span> commit <span style="color: #339933;">-</span>m <span style="color: #ff0000;">&quot;Added CanCan&quot;</span></pre></div></div>

<p>jQuery</p>
<p>We used the -J option when we created the app so that we could use jQuery instead of Prototype. In your shell, run the jQuery generator:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
rails g jquery<span style="color: #339933;">:</span>install <span style="color: #339933;">--</span>ui</pre></div></div>

<p>This’ll do 3 main things: remove the existing protoypejs-based javascript files (which, in our case, aren’t there anyway), drop in the latest jQuery, and drop in the jQuery version of the Rails Unobtrusive Javascript (UJS) Adapter. Since jQueryUI is pretty cool too, we drop that in too with the –ui option.</p>
<p>In order to make the :defaults argument to javascript_include_tag load the .js files in the right order, we need to modify config/application.rb. Look for:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
config.<span style="color: #202020;">action_view</span>.<span style="color: #202020;">javascript_expansions</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">:</span>defaults<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">%</span>w<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
and change it to<span style="color: #339933;">:</span>
&nbsp;
config.<span style="color: #202020;">action_view</span>.<span style="color: #202020;">javascript_expansions</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">:</span>defaults<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>
  <span style="color: #339933;">%</span>w<span style="color: #009900;">&#40;</span>jquery.<span style="color: #202020;">min</span> jquery<span style="color: #339933;">-</span>ui.<span style="color: #202020;">min</span> rails<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Notice that we load the minified versions which were downloaded by the generator.</p>
<p>Commit it:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
git add .
<span style="color: #202020;">git</span> commit <span style="color: #339933;">-</span>m <span style="color: #ff0000;">&quot;Added jQuery&quot;</span>
Compass<span style="color: #339933;">/</span>Haml<span style="color: #339933;">/</span>Sass<span style="color: #339933;">/</span>Blueprintcss</pre></div></div>

<p>Haml is a template langauge like erb. When we added “gem ‘haml’” to the Gemfile, we made Rails recognize that files with the .haml extension contain Haml markup. Sass is a superset of css3 that helps keep your stylesheets clean. Blueprintcss is a css framework that provides easy to use reset, grid, and typographical styles. Compass ties all this together and provides a way to integrate it into your app.</p>
<p>Run this to install Compass into your app using Blueprintcss:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
compass init rails . <span style="color: #339933;">--</span>using blueprint<span style="color: #339933;">/</span>semantic</pre></div></div>

<p>Compass will ask you a few questions. Just say yes to both of them.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
Compass recommends that you keep your stylesheets in app<span style="color: #339933;">/</span>stylesheets
  instead of the Sass <span style="color: #b1b100;">default</span> location of public<span style="color: #339933;">/</span>stylesheets<span style="color: #339933;">/</span>sass.
  <span style="color: #202020;">Is</span> this OK<span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span>Y<span style="color: #339933;">/</span>n<span style="color: #009900;">&#41;</span> Y
&nbsp;
Compass recommends that you keep your compiled css in public<span style="color: #339933;">/</span>stylesheets<span style="color: #339933;">/</span>compiled<span style="color: #339933;">/</span>
  instead the Sass <span style="color: #b1b100;">default</span> of public<span style="color: #339933;">/</span>stylesheets<span style="color: #339933;">/</span>.
  <span style="color: #202020;">However</span><span style="color: #339933;">,</span> <span style="color: #b1b100;">if</span> you<span style="color: #ff0000;">'re exclusively using Sass, then public/stylesheets/ is recommended.
  Emit compiled stylesheets to public/stylesheets/compiled/? (Y/n) Y</span></pre></div></div>

<p>After that, it’ll drop a bunch of files into the app and finish up with some instructions. We’ve already done the first suggestion, added Compass to the Gemfile. The second suggestion gives us the opportunity to put together our layout.</p>
<p>Create app/views/layout/application.html.haml and place this inside:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
&nbsp;
<span style="color: #339933;">!!!</span> XML
<span style="color: #339933;">!!!</span>
<span style="color: #339933;">%</span>html
  <span style="color: #339933;">%</span>head
    <span style="color: #339933;">%</span>title Awesome App
    <span style="color: #339933;">=</span> javascript_include_tag <span style="color: #339933;">:</span>defaults
    <span style="color: #339933;">=</span> csrf_meta_tag
    <span style="color: #339933;">=</span> stylesheet_link_tag <span style="color: #339933;">:</span>all
    <span style="color: #339933;">=</span> stylesheet_link_tag <span style="color: #ff0000;">'compiled/screen.css'</span><span style="color: #339933;">,</span> <span style="color: #339933;">:</span>media <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'screen, projection'</span>
    <span style="color: #339933;">=</span> stylesheet_link_tag <span style="color: #ff0000;">'compiled/print.css'</span><span style="color: #339933;">,</span>  <span style="color: #339933;">:</span>media <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'print'</span>
    <span style="color: #339933;">/</span><span style="color: #009900;">&#91;</span><span style="color: #b1b100;">if</span> lt IE <span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span>
      <span style="color: #339933;">=</span> stylesheet_link_tag <span style="color: #ff0000;">'compiled/ie.css'</span><span style="color: #339933;">,</span> <span style="color: #339933;">:</span>media <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'screen, projection'</span>
&nbsp;
  <span style="color: #339933;">%</span>body.<span style="color: #202020;">bp</span>.<span style="color: #202020;">two</span><span style="color: #339933;">-</span>col
&nbsp;
    <span style="color: #339933;">#container</span>
&nbsp;
      <span style="color: #339933;">#header</span>
        <span style="color: #339933;">%</span>h1 Awesome App Header
&nbsp;
      <span style="color: #339933;">#sidebar</span>
        <span style="color: #339933;">%</span>div item <span style="color: #0000dd;">1</span>
        <span style="color: #339933;">%</span>div item <span style="color: #0000dd;">2</span>
        <span style="color: #339933;">%</span>div item <span style="color: #0000dd;">3</span>
        <span style="color: #339933;">%</span>div item <span style="color: #0000dd;">4</span>
&nbsp;
      <span style="color: #339933;">#content</span>
&nbsp;
        <span style="color: #339933;">%</span>p.<span style="color: #202020;">notice</span><span style="color: #339933;">=</span> notice
        <span style="color: #339933;">%</span>p.<span style="color: #202020;">error</span><span style="color: #339933;">=</span> alert
        <span style="color: #339933;">%</span>p.<span style="color: #202020;">success</span><span style="color: #339933;">=</span> notice
&nbsp;
        <span style="color: #339933;">=</span> yield
&nbsp;
      <span style="color: #339933;">#footer</span>
        <span style="color: #339933;">%</span>h3 Awesome App Footer</pre></div></div>

<p>There are a few things to notice in there. First, it’s Haml. Second, we’ve included the stylesheet info from the compass command output in the head. Third, we’re using the built-in Blueprintcss 2-column layout. Finally, we’ve added the notice and alert elements that Devise asked for earlier. There’s also a success element in there to show off some of the coloring that Blueprintcss gives you.</p>
<p>If you try to look at it now, it won’t work. Sit tight, we’re close.</p>
<p>Making Compass Just Work</p>
<p>The Compass documentation seems to lack a simple explanation of how to see if things just work. Here it is:</p>
<p>Create app/stylesheets/partials/_application.scss, and place this inside:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">&nbsp;
<span style="color: #339933;">#container {</span>
  @include showgrid<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Use this file to get started adding your own styles. The showgrid mixin is useful for debugging your Blueprintcss grid. Delete it or comment it out when you’re done.</p>
<p>Then, add this to app/stylesheets/screen.scss:</p>
<p>// Add the application styles.<br />
@import &#8220;partials/application&#8221;;<br />
This makes sure that your own styles are available when you get around to adding them.</p>
<p>Commit it:</p>
<p>git add .<br />
git commit -m &#8220;Added Compass&#8221;<br />
Last Steps Before Starting the App</p>
<p>Delete public/index.html:</p>
<p>rm public/index.html<br />
Earlier, Devise instructed us to setup the root route in routes.rb. The problem is the route we added won’t actually work until we have a home controller with an index action.</p>
<p>Shell it:</p>
<p>rails g controller home index<br />
Notice that the views generated use Haml. That works because we added the ‘haml-rails’ gem to the Gemfile.</p>
<p>Then, so that we can see Devise in action:</p>
<p>rails g controller vip index<br />
In app/controllers/vip_controller.rb, add:</p>
<p>before_filter :authenticate_user!<br />
Commit it:</p>
<p>git add .<br />
git commit -m &#8220;Added Home and Vip controllers and views&#8221;<br />
Start It Up</p>
<p>passenger start<br />
Now go to: http://localhost:3000</p>
<p>Nice! See the grid? Clean.</p>
<p>How about this one? http://localhost:3000/vip/index</p>
<p>Go ahead. Mess with the login stuff. It’ll just kinda work.</p>
<p>One More Thing, metric_fu</p>
<p>Add this to your Rakefile:</p>
<p>require &#8216;metric_fu&#8217;<br />
MetricFu::Configuration.run do |config|<br />
  config.rcov[:test_files] = ['spec/**/*_spec.rb']<br />
  config.rcov[:rcov_opts] << &#8220;-Ispec&#8221; # Needed to find spec_helper<br />
end<br />
Get your metrics by running this:</p>
<p>rake metrics:all<br />
Commit it:</p>
<p>git add .<br />
git commit -m &#8220;Added metric_fu&#8221;<br />
Conclusion</p>
<p>Okay, so it doesn’t really do anything… yet. That’s okay. You’re smart. Make.</p>
<p>There were a few things in the list at the top that I didn’t go into more detail about (Capistrano, Passenger, Factory Girl, and Shoulda). That’s because they’re ready to go; inclusion in the Gemfile was enough. Just start using ‘em.</p>
<p>Links</p>
<p>Here’s a list of links to the documentation and articles I used to pull this together:</p>
<p>http://relishapp.com/rspec/rspec-rails<br />
http://github.com/aslakhellesoy/cucumber-rails/blob/master/README.rdoc<br />
http://github.com/thoughtbot/shoulda<br />
http://github.com/thoughtbot/factory_girl_rails<br />
http://mongoid.org/docs/installation<br />
http://mongoid.org/docs/integration<br />
http://mongoid.org/docs/extensions<br />
http://github.com/plataformatec/devise<br />
https://github.com/ryanb/cancan<br />
http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/<br />
https://github.com/indirect/jquery-rails<br />
http://haml-lang.com/<br />
http://sass-lang.com/<br />
http://compass-style.org/<br />
http://blueprintcss.org/<br />
https://github.com/joshuaclayton/blueprint-css/wiki</p>
]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/rubyruby-on-rails/2011/07/19/rails-3-rspec-cucumber-jquery-devise-mongoid-and-compass%e8%bd%ac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>小组级git服务器搭建（转)</title>
		<link>http://weixuhong.com/linuxunix/2011/07/18/%e5%b0%8f%e7%bb%84%e7%ba%a7git%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%90%ad%e5%bb%ba%ef%bc%88%e8%bd%ac/</link>
		<comments>http://weixuhong.com/linuxunix/2011/07/18/%e5%b0%8f%e7%bb%84%e7%ba%a7git%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%90%ad%e5%bb%ba%ef%bc%88%e8%bd%ac/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 07:33:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux/Unix]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=541</guid>
		<description><![CDATA[来自：http://blog.prosight.me/index.php/2009/11/485
如果使用git的人数较少，可以使用下面的步骤快速部署一个git服务器环境。
1. 生成 SSH 公钥
每个需要使用git服务器的工程师，自己需要生成一个ssh公钥
进入自己的~/.ssh目录，看有没有用 文件名 和 文件名.pub 来命名的一对文件，这个 文件名 通常是 id_dsa 或者 id_rsa。 .pub 文件是公钥，另一个文件是密钥。假如没有这些文件（或者干脆连 .ssh 目录都没有），你可以用 ssh-keygen 的程序来建立它们，该程序在 Linux/Mac 系统由 SSH 包提供， 在 Windows 上则包含在 MSysGit 包里:

$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key &#40;/Users/schacon/.ssh/id_rsa&#41;: 
Enter passphrase &#40;empty for no passphrase&#41;: 
Enter same passphrase again: 
Your identification has [...]]]></description>
			<content:encoded><![CDATA[<p>来自：http://blog.prosight.me/index.php/2009/11/485</p>
<p>如果使用git的人数较少，可以使用下面的步骤快速部署一个git服务器环境。<br />
1. 生成 SSH 公钥<br />
每个需要使用git服务器的工程师，自己需要生成一个ssh公钥<br />
进入自己的~/.ssh目录，看有没有用 文件名 和 文件名.pub 来命名的一对文件，这个 文件名 通常是 id_dsa 或者 id_rsa。 .pub 文件是公钥，另一个文件是密钥。假如没有这些文件（或者干脆连 .ssh 目录都没有），你可以用 ssh-keygen 的程序来建立它们，该程序在 Linux/Mac 系统由 SSH 包提供， 在 Windows 上则包含在 MSysGit 包里:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ ssh<span style="color: #339933;">-</span>keygen 
Generating public<span style="color: #339933;">/</span>private rsa key pair.
<span style="color: #202020;">Enter</span> file in which to save the key <span style="color: #009900;">&#40;</span><span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>schacon<span style="color: #339933;">/</span>.<span style="color: #202020;">ssh</span><span style="color: #339933;">/</span>id_rsa<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> 
Enter passphrase <span style="color: #009900;">&#40;</span>empty <span style="color: #b1b100;">for</span> no passphrase<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> 
Enter same passphrase again<span style="color: #339933;">:</span> 
Your identification has been saved in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>schacon<span style="color: #339933;">/</span>.<span style="color: #202020;">ssh</span><span style="color: #339933;">/</span>id_rsa.
<span style="color: #202020;">Your</span> public key has been saved in <span style="color: #339933;">/</span>Users<span style="color: #339933;">/</span>schacon<span style="color: #339933;">/</span>.<span style="color: #202020;">ssh</span><span style="color: #339933;">/</span>id_rsa.<span style="color: #202020;">pub</span>.
<span style="color: #202020;">The</span> key fingerprint is<span style="color: #339933;">:</span>
<span style="color: #0000dd;">43</span><span style="color: #339933;">:</span>c5<span style="color: #339933;">:</span>5b<span style="color: #339933;">:</span><span style="color:#800080;">5f</span><span style="color: #339933;">:</span>b1<span style="color: #339933;">:</span>f1<span style="color: #339933;">:</span><span style="color: #0000dd;">50</span><span style="color: #339933;">:</span><span style="color: #0000dd;">43</span><span style="color: #339933;">:</span>ad<span style="color: #339933;">:</span><span style="color: #0000dd;">20</span><span style="color: #339933;">:</span>a6<span style="color: #339933;">:</span><span style="color: #0000dd;">92</span><span style="color: #339933;">:</span>6a<span style="color: #339933;">:</span><span style="color:#800080;">1f</span><span style="color: #339933;">:</span>9a<span style="color: #339933;">:</span>3a schacon@agadorlaptop.<span style="color: #202020;">local</span></pre></div></div>

<p>它先要求你确认保存公钥的位置（.ssh/id_rsa），然后它会让你重复一个密码两次，如果不想在使用公钥的时候输入密码，可以留空。<br />
现在，所有做过这一步的用户都得把它们的公钥给你或者 Git 服务器的管理者（假设 SSH 服务被设定为使用公钥机制）。他们只需要复制 .pub 文件的内容然后 e-</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ cat ~<span style="color: #339933;">/</span>.<span style="color: #202020;">ssh</span><span style="color: #339933;">/</span>id_rsa.<span style="color: #202020;">pub</span> 
ssh<span style="color: #339933;">-</span>rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom<span style="color: #339933;">/</span>BWDSU
GPl<span style="color: #339933;">+</span>nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3
Pbv7kOdJ<span style="color: #339933;">/</span>MTyBlWXFCR<span style="color: #339933;">+</span>HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK<span style="color: #339933;">/</span>7XA
t3FaoJoAsncM1Q9x5<span style="color: #339933;">+</span>3V0Ww68<span style="color: #339933;">/</span>eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw<span style="color: #339933;">/</span>Pb0rwert<span style="color: #339933;">/</span>En
mZ<span style="color: #339933;">+</span>AW4OZPnTPI89ZPmVMLuayrD2cE86Z<span style="color: #339933;">/</span>il8b<span style="color: #339933;">+</span>gw3r3<span style="color: #339933;">+</span>1nKatmIkjn2so1d01QraTlMqVSsbx
NrRFi9wrf<span style="color: #339933;">+</span>M7Q<span style="color: #339933;">==</span> schacon@agadorlaptop.<span style="color: #202020;">local</span></pre></div></div>

<p>2. 架设服务器<br />
首先，创建一个 ‘git’ 用户并为其创建一个 .ssh 目录，在用户主目录下:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ sudo adduser git
$ su git
$ cd
$ mkdir .<span style="color: #202020;">ssh</span></pre></div></div>

<p>接下来，把开发者的 SSH 公钥添加到这个用户的 authorized_keys 文件中。假设你通过 e-mail 收到了几个公钥并存到了临时文件里。只要把它们加入 authorized_keys 文件</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ cat <span style="color: #339933;">/</span>tmp<span style="color: #339933;">/</span>id_rsa.<span style="color: #202020;">john</span>.<span style="color: #202020;">pub</span> <span style="color: #339933;">&gt;&gt;</span> ~<span style="color: #339933;">/</span>.<span style="color: #202020;">ssh</span><span style="color: #339933;">/</span>authorized_keys
$ cat <span style="color: #339933;">/</span>tmp<span style="color: #339933;">/</span>id_rsa.<span style="color: #202020;">josie</span>.<span style="color: #202020;">pub</span> <span style="color: #339933;">&gt;&gt;</span> ~<span style="color: #339933;">/</span>.<span style="color: #202020;">ssh</span><span style="color: #339933;">/</span>authorized_keys
$ cat <span style="color: #339933;">/</span>tmp<span style="color: #339933;">/</span>id_rsa.<span style="color: #202020;">jessica</span>.<span style="color: #202020;">pub</span> <span style="color: #339933;">&gt;&gt;</span> ~<span style="color: #339933;">/</span>.<span style="color: #202020;">ssh</span><span style="color: #339933;">/</span>authorized_keys</pre></div></div>

<p>现在可以使用 –bare 选项运行 git init 来设定一个空仓库，这会初始化一个不包含工作目录的仓库。</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ cd <span style="color: #339933;">/</span>opt<span style="color: #339933;">/</span>git
$ mkdir project.<span style="color: #202020;">git</span>
$ cd project.<span style="color: #202020;">git</span>
$ git <span style="color: #339933;">--</span>bare init</pre></div></div>

<p>这时，开发人员就可以把它加为远程仓库，推送一个分支，从而把第一个版本的工程上传到仓库里了。值得注意的是，每次添加一个新项目都需要通过 shell 登入主机并创建一个纯仓库。我们不妨以 gitserver 作为 git 用户和仓库所在的主机名。如果你在网络内部运行该主机，并且在 DNS 中设定 gitserver 指向该主机，那么以下这些命令都是可用的：</p>
<p># 在一个工程师的电脑上</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ cd myproject
$ git init
$ git add .
$ git commit <span style="color: #339933;">-</span>m <span style="color: #ff0000;">'initial commit'</span>
$ git remote add origin git@gitserver<span style="color: #339933;">:/</span>opt<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>project.<span style="color: #202020;">git</span>
$ git push origin master</pre></div></div>

<p>这样，其他人的克隆和推送也一样变得很简单：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ git clone git@gitserver<span style="color: #339933;">:/</span>opt<span style="color: #339933;">/</span>git<span style="color: #339933;">/</span>project.<span style="color: #202020;">git</span>
$ vim README
$ git commit <span style="color: #339933;">-</span>am <span style="color: #ff0000;">'fix for the README file'</span>
$ git push origin master</pre></div></div>

<p>用这个方法可以很快捷的为少数几个开发者架设一个可读写的 Git 服务。<br />
作为一个额外的防范措施，你可以用 Git 自带的 git-shell 简单工具来把 git 用户的活动限制在仅与 Git 相关。把它设为 git 用户登入的 shell，那么该用户就不能拥有主机正常的 shell 访问权。为了实现这一点，需要指明用户的登入shell 是 git-shell ，而不是 bash 或者 csh。你可能得编辑 /etc/passwd 文件</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ sudo vim <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>passwd</pre></div></div>

<p>在文件末尾，你应该能找到类似这样的行：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">git<span style="color: #339933;">:</span>x<span style="color: #339933;">:</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">:</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">::/</span>home<span style="color: #339933;">/</span>git<span style="color: #339933;">:/</span>bin<span style="color: #339933;">/</span>sh</pre></div></div>

<p>把 bin/sh 改为 /usr/bin/git-shell （或者用 which git-shell 查看它的位置）。该行修改后的样子如下：</p>
<p>git:x:1000:1000::/home/git:/usr/bin/git-shell<br />
现在 git 用户只能用 SSH 连接来推送和获取 Git 仓库，而不能直接使用主机 shell。尝试登录的话，你会看到下面这样的拒绝信息：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ ssh git@gitserver</pre></div></div>

<p>fatal: What do you think I am? A shell? （你以为我是个啥？shell吗？)<br />
Connection to gitserver closed. （gitserver 连接已断开。）</p>
]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/linuxunix/2011/07/18/%e5%b0%8f%e7%bb%84%e7%ba%a7git%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%90%ad%e5%bb%ba%ef%bc%88%e8%bd%ac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>常用gem</title>
		<link>http://weixuhong.com/rubyruby-on-rails/2011/07/18/%e5%b8%b8%e7%94%a8gem/</link>
		<comments>http://weixuhong.com/rubyruby-on-rails/2011/07/18/%e5%b8%b8%e7%94%a8gem/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 04:55:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby/Ruby on Rails]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=537</guid>
		<description><![CDATA[
&#160;
source 'http://rubygems.org'
&#160;
# --------------------
#   Rails
# --------------------
# gem 'rails',                     '~&#62; 3.0.0'
gem 'rails',                     :git =&#62; 'git://github.com/rails/rails.git', [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
source <span style="color:#996600;">'http://rubygems.org'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># --------------------</span>
<span style="color:#008000; font-style:italic;">#   Rails</span>
<span style="color:#008000; font-style:italic;"># --------------------</span>
<span style="color:#008000; font-style:italic;"># gem 'rails',                     '~&gt; 3.0.0'</span>
gem <span style="color:#996600;">'rails'</span>,                     <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'git://github.com/rails/rails.git'</span>, <span style="color:#ff3333; font-weight:bold;">:branch</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'3-0-stable'</span>
<span style="color:#008000; font-style:italic;"># gem 'rails',                     :path =&gt; '/Users/fred/Downloads/Repos/Rails/rails-master'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># --------------------</span>
<span style="color:#008000; font-style:italic;">#   Database</span>
<span style="color:#008000; font-style:italic;"># --------------------</span>
gem <span style="color:#996600;">'mysql2'</span>,                    <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'git://github.com/brianmario/mysql2.git'</span>
gem <span style="color:#996600;">'datamappify'</span>,               <span style="color:#996600;">'&gt;= 0.2.1'</span>
gem <span style="color:#996600;">'by_star'</span>,                   <span style="color:#996600;">'~&gt; 0.9.0'</span>
<span style="color:#008000; font-style:italic;"># gem 'slim_scrooge',              '~&gt; 1.0.10', :group =&gt; :production</span>
<span style="color:#008000; font-style:italic;"># gem 'meta_where',                '&gt;= 0.9.3'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># --------------------</span>
<span style="color:#008000; font-style:italic;">#   Resources</span>
<span style="color:#008000; font-style:italic;"># --------------------</span>
gem <span style="color:#996600;">'inherited_resources'</span>,       <span style="color:#996600;">'~&gt; 1.1.2'</span>
gem <span style="color:#996600;">'inherited_resources_views'</span>
gem <span style="color:#996600;">'devise'</span>,                    <span style="color:#996600;">'~&gt; 1.1.2'</span>
gem <span style="color:#996600;">'cancan'</span>,                    <span style="color:#996600;">'~&gt; 1.3.0'</span>
gem <span style="color:#996600;">'carrierwave'</span>,               <span style="color:#996600;">'~&gt; 0.5.0'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># --------------------</span>
<span style="color:#008000; font-style:italic;">#   Presentation</span>
<span style="color:#008000; font-style:italic;"># --------------------</span>
gem <span style="color:#996600;">'haml'</span>,                      <span style="color:#996600;">'~&gt; 3.0.18'</span>
gem <span style="color:#996600;">'compass'</span>
gem <span style="color:#996600;">'simple_form'</span>,               <span style="color:#996600;">'~&gt; 1.2.0'</span>
gem <span style="color:#996600;">'simple-navigation'</span>,         <span style="color:#996600;">'~&gt; 2.7.0'</span>
gem <span style="color:#996600;">'will_paginate'</span>,             <span style="color:#996600;">'~&gt; 3.0.pre'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># --------------------</span>
<span style="color:#008000; font-style:italic;">#   Assets</span>
<span style="color:#008000; font-style:italic;"># --------------------</span>
gem <span style="color:#996600;">'rails_config'</span>
gem <span style="color:#996600;">'rdiscount'</span>,                 <span style="color:#996600;">'&gt;= 1.6.5'</span>
gem <span style="color:#996600;">'sanitize'</span>
gem <span style="color:#996600;">'rubyzip'</span>,                   <span style="color:#ff3333; font-weight:bold;">:require</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'zip/zip'</span>
gem <span style="color:#996600;">'csv-mapper'</span>,                <span style="color:#996600;">'&gt;= 0.5.0'</span>
gem <span style="color:#996600;">'ffaker'</span>,                    <span style="color:#996600;">'&gt;= 0.4.0'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># --------------------</span>
<span style="color:#008000; font-style:italic;">#   Server/Deployment</span>
<span style="color:#008000; font-style:italic;"># --------------------</span>
gem <span style="color:#996600;">'dalli'</span>
gem <span style="color:#996600;">'thin'</span>
gem <span style="color:#996600;">'capistrano-ext'</span>
gem <span style="color:#996600;">'deployer'</span>,                  <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'git://github.com/meskyanichi/deployer.git'</span>
gem <span style="color:#996600;">'hoptoad_notifier'</span>
gem <span style="color:#996600;">'newrelic_rpm'</span>
&nbsp;
group <span style="color:#ff3333; font-weight:bold;">:development</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'bullet'</span>,                  <span style="color:#996600;">'~&gt; 2.0.0.rc1'</span>
  gem <span style="color:#996600;">'hpricot'</span>,                 <span style="color:#996600;">'&gt;= 0.8.2'</span>
  gem <span style="color:#996600;">'ruby_parser'</span>,             <span style="color:#996600;">'&gt;= 2.0.4'</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
group <span style="color:#ff3333; font-weight:bold;">:development</span>, <span style="color:#ff3333; font-weight:bold;">:test</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  gem <span style="color:#996600;">'rspec-rails'</span>,             <span style="color:#996600;">'~&gt; 2.0.0.beta.22'</span>
  gem <span style="color:#996600;">'steak'</span>,                   <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'git://github.com/cavalle/steak.git'</span>
  gem <span style="color:#996600;">'capybara'</span>,                <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'git://github.com/jnicklas/capybara.git'</span>
  gem <span style="color:#996600;">'delorean'</span>
  gem <span style="color:#996600;">'database_cleaner'</span>
  gem <span style="color:#996600;">'launchy'</span>
  gem <span style="color:#996600;">'parallel_tests'</span>,          <span style="color:#ff3333; font-weight:bold;">:git</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'git://github.com/grosser/parallel_tests.git'</span>
  <span style="color:#008000; font-style:italic;"># gem 'parallel_tests',          :path =&gt; '/Users/fred/Downloads/Repos/Rails/fredwu-parallel_tests'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>也可以参考：http://thoughtrails.com/episodes/24-popular-and-useful-plugins-for-rails3</p>
]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/rubyruby-on-rails/2011/07/18/%e5%b8%b8%e7%94%a8gem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RuntimeError (!!! Missing the mysql2 gem. Add it to your Gemfile: gem &#8216;mysql2&#8242;):</title>
		<link>http://weixuhong.com/rubyruby-on-rails/2011/07/07/runtimeerror-missing-the-mysql2-gem-add-it-to-your-gemfile-gem-mysql2/</link>
		<comments>http://weixuhong.com/rubyruby-on-rails/2011/07/07/runtimeerror-missing-the-mysql2-gem-add-it-to-your-gemfile-gem-mysql2/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 02:38:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby/Ruby on Rails]]></category>

		<guid isPermaLink="false">http://weixuhong.com/?p=533</guid>
		<description><![CDATA[在Rails3 出现这个错误，做以下工作:
1. 在Gemfile

gem 'mysql2', '~&#62; 0.2.6'

2.

 bundle update

3. 在datababse.yml

development:
  adapter: mysql2
  encoding: utf8
  database: devise
  # pool: 5
  username: root
  password:
  reconnect: true
  socket: /tmp/mysql.sock

参考: http://stackoverflow.com/questions/4297253/install-mysql2-gem-on-snow-leopard-for-rails-3-with-rvm
]]></description>
			<content:encoded><![CDATA[<p>在Rails3 出现这个错误，做以下工作:</p>
<p>1. 在Gemfile</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">gem <span style="color:#996600;">'mysql2'</span>, <span style="color:#996600;">'~&gt; 0.2.6'</span></pre></div></div>

<p>2.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"> bundle update</pre></div></div>

<p>3. 在datababse.yml</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">development:
  adapter: mysql2
  encoding: utf8
  database: devise
  <span style="color:#008000; font-style:italic;"># pool: 5</span>
  username: root
  password:
  reconnect: <span style="color:#0000FF; font-weight:bold;">true</span>
  socket: <span style="color:#006600; font-weight:bold;">/</span>tmp<span style="color:#006600; font-weight:bold;">/</span>mysql.<span style="color:#9900CC;">sock</span></pre></div></div>

<p>参考: http://stackoverflow.com/questions/4297253/install-mysql2-gem-on-snow-leopard-for-rails-3-with-rvm</p>
]]></content:encoded>
			<wfw:commentRss>http://weixuhong.com/rubyruby-on-rails/2011/07/07/runtimeerror-missing-the-mysql2-gem-add-it-to-your-gemfile-gem-mysql2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

