<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6758697817819098194</id><updated>2024-09-23T01:55:18.847+01:00</updated><category term="Ruby/ Ruby on Rails"/><category term="Git"/><category term="Linux"/><category term="Processing"/><category term="English"/><category term="Essays and Reports"/><category term="Links"/><category term="Box2D.js"/><category term="Mac"/><category term="MySQL"/><category term="Sass"/><title type='text'>Engineer Flies エンジニアは空を飛ぶ</title><subtitle type='html'>Ruby, The Processing Language　などについてのブログ</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://engineerflies.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/-/Ruby%2F+Ruby+on+Rails'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/search/label/Ruby%2F%20Ruby%20on%20Rails'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/-/Ruby%2F+Ruby+on+Rails/-/Ruby%2F+Ruby+on+Rails?start-index=26&amp;max-results=25'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>42</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-3326946423514639412</id><published>2015-09-20T10:40:00.001+01:00</published><updated>2015-09-20T10:40:49.557+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>１行で複数の変数を設定するのは気をつけよう</title><content type='html'>&lt;div class=&quot;p1&quot;&gt;
`a, b = b, a`と`a = b; b = a;`って違うんですね。&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
```ruby&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;gt; a, b, c =&amp;nbsp;&lt;span class=&quot;s1&quot;&gt;&#39;a&#39;&lt;/span&gt;,&amp;nbsp;&lt;span class=&quot;s1&quot;&gt;&#39;b&#39;&lt;/span&gt;,&amp;nbsp;&lt;span class=&quot;s1&quot;&gt;&#39;c&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;=&amp;gt; [&lt;/span&gt;&quot;a&quot;&lt;span class=&quot;s2&quot;&gt;,&amp;nbsp;&lt;/span&gt;&quot;b&quot;&lt;span class=&quot;s2&quot;&gt;,&amp;nbsp;&lt;/span&gt;&quot;c&quot;&lt;span class=&quot;s2&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;gt; a = b; b = a;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;gt; [a, b, c]&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;=&amp;gt; [&lt;/span&gt;&quot;b&quot;&lt;span class=&quot;s1&quot;&gt;,&amp;nbsp;&lt;/span&gt;&quot;b&quot;&lt;span class=&quot;s1&quot;&gt;,&amp;nbsp;&lt;/span&gt;&quot;c&quot;&lt;span class=&quot;s1&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
# リセット&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;gt; a, b, c =&amp;nbsp;&lt;span class=&quot;s1&quot;&gt;&#39;a&#39;&lt;/span&gt;,&amp;nbsp;&lt;span class=&quot;s1&quot;&gt;&#39;b&#39;&lt;/span&gt;,&amp;nbsp;&lt;span class=&quot;s1&quot;&gt;&#39;c&#39;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;=&amp;gt; [&lt;/span&gt;&quot;a&quot;&lt;span class=&quot;s2&quot;&gt;,&amp;nbsp;&lt;/span&gt;&quot;b&quot;&lt;span class=&quot;s2&quot;&gt;,&amp;nbsp;&lt;/span&gt;&quot;c&quot;&lt;span class=&quot;s2&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;gt; a, b = b, a&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&amp;gt; [a, b, c]&lt;/div&gt;
&lt;div class=&quot;p1&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s1&quot;&gt;=&amp;gt; [&lt;/span&gt;&quot;b&quot;&lt;span class=&quot;s1&quot;&gt;,&amp;nbsp;&lt;/span&gt;&quot;a&quot;&lt;span class=&quot;s1&quot;&gt;,&amp;nbsp;&lt;/span&gt;&quot;c&quot;&lt;span class=&quot;s1&quot;&gt;]&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot;&gt;
&lt;span class=&quot;s2&quot;&gt;```&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;s2&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span class=&quot;s2&quot;&gt;つまり１行の場合はそれ以前の行の変数の状態を保持した状態でそれぞれの変数へ同時に代入が行われる。&lt;/span&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/3326946423514639412'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/3326946423514639412'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2015/09/blog-post.html' title='１行で複数の変数を設定するのは気をつけよう'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-7236712443752184579</id><published>2014-01-01T04:21:00.001+00:00</published><updated>2014-01-01T04:21:23.470+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>has_and_belongs_to_many associationで counter_cacheを有効にする</title><content type='html'>has_and_belongs_to_many associationで counter_cacheを有効にするサンプル。&lt;br /&gt;
&lt;br /&gt;
以下は Category has_and_belongs_to_many Website な関係が成立しています。HABTMでcounter_cacheを実施するには has_and_belongs_to_manyに:after_add, :after_removeなどのオプションを渡してフックするメソッドをしてあげれば良いです。&lt;br /&gt;
&lt;br /&gt;
そうすることで website.categries = [category_foo, category_bar] としたときに以前のcategoriesとの差分についてcounter_cacheをincrement/decrementしてくれる。&lt;br /&gt;
&lt;br /&gt;
Website自身のフック :after_save, :after_create, :after_destroyは関連を更新したときにはトリガーされないです。&lt;br /&gt;
&lt;br /&gt;
*. #make!はmachinistからデータを作成しています&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/suzukimilanpaak/8204980.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/7236712443752184579'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/7236712443752184579'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2014/01/hasandbelongstomany-association.html' title='has_and_belongs_to_many associationで counter_cacheを有効にする'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-5494054488261392409</id><published>2014-01-01T01:29:00.001+00:00</published><updated>2014-01-01T04:21:43.530+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Rails 4　エラーメッセージを完全に上書きする</title><content type='html'>メッセージを上書きしたいときはオプションで presence: { message: &#39;Select at least one category&#39; } の様にメッセージを渡してあげれば良いです。&lt;br /&gt;
だけど、それだと主語が先頭に来てしまい&quot;Category Select at least one category&quot;というエラーメッセージになってしまう。&lt;br /&gt;
&lt;br /&gt;
全てのメッセージを上書きしたいときはlambdaを渡してあげればよい。&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;ruby&#39; name=&#39;code&#39;&gt;validates :categories, presence: { message: -&gt; {|location, error| raise [location, error].inspect }  }

# =&gt; [:&quot;activerecord.errors.models.website.attributes.categories.blank&quot;, {:model=&gt;&quot;Website&quot;, :attribute=&gt;&quot;Categories&quot;, :value=&gt;#＜ActiveRecord::Associations::CollectionProxy []&gt; }]

&lt;/pre&gt;&lt;br /&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5494054488261392409'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5494054488261392409'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2014/01/rails-4.html' title='Rails 4　エラーメッセージを完全に上書きする'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-1361422717302304569</id><published>2013-03-06T02:01:00.000+00:00</published><updated>2013-03-06T02:01:04.782+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Links"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Railsはどうやってコネクションをプールしているの？</title><content type='html'>&lt;br /&gt;
- Rackがコネクションをプールしている&lt;br /&gt;
- 一個のスレッドは一個のコネクションしか持てない&lt;br /&gt;
http://stackoverflow.com/questions/5131772/how-does-the-rails-connection-pooling-work&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- Rails2.2以前&lt;br /&gt;
&amp;nbsp; Rails2.2以前のスレッドとコネクションの関係であればこちらの記事が分かりやすいです。良記事！&lt;br /&gt;
&amp;nbsp; http://fmkt.blog65.fc2.com/blog-entry-138.html&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/1361422717302304569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/1361422717302304569'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2013/03/rails.html' title='Railsはどうやってコネクションをプールしているの？'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-1794042888620600968</id><published>2013-02-07T04:46:00.001+00:00</published><updated>2013-02-07T04:46:23.638+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Links"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Capistrano関係のリンク</title><content type='html'>- Wiki home&lt;br /&gt;
https://github.com/capistrano/capistrano/wiki&lt;br /&gt;
&lt;br /&gt;
- よく使う変数 &lt;br /&gt;
https://github.com/capistrano/capistrano/wiki/2.x-Significant-Configuration-Variables&lt;br /&gt;
&lt;br /&gt;
- CapistranoのTask一覧&lt;br /&gt;
https://github.com/capistrano/capistrano/wiki/Capistrano-Tasks&lt;br /&gt;
&lt;br /&gt;
- Capistranoの予約変数&lt;br /&gt;
http://theadmin.org/articles/capistrano-variables/&lt;br /&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/1794042888620600968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/1794042888620600968'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2013/02/capistrano.html' title='Capistrano関係のリンク'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-5916686986573255418</id><published>2013-01-24T03:04:00.001+00:00</published><updated>2013-01-24T03:04:01.262+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Links"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>RSpecのベストプラクティス</title><content type='html'>オンライン上のRSpecのベストプラクティスって結構限られていますよね。Specの書き方の基本が分かると”ControllerのexampleでViewやModel出力のバリエイションを担保しない。”といったような一定のノウハウにそってスペックを書きつつコーディングもきれいに整頓していきたくなるところ。&lt;br /&gt;
&lt;br /&gt;
- &lt;a href=&#39;http://betterspecs.org/&#39;&gt;Better Specs&lt;/a&gt;&lt;br /&gt;
  Specそのものの書き方を学ぶならここ。Githubの議論付きで紹介しています。&lt;br /&gt;
&lt;br /&gt;
- &lt;a href=&#39;https://www.relishapp.com/rspec/rspec-rails/v/2-12-2/docs&#39;&gt;RSpec Rails in Relish&lt;/a&gt;&lt;br /&gt;
  ベストプラクティスと銘打っているわけではありませんがRailsのMVCHのスペックの書き方をここで学ぶことができます。</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5916686986573255418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5916686986573255418'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2013/01/rspec.html' title='RSpecのベストプラクティス'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-7070521224594752265</id><published>2013-01-08T16:01:00.001+00:00</published><updated>2013-01-08T16:09:18.853+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="Sass"/><title type='text'>[Sass] @extendの覚えておくべき動作とplaceholder seloctorの使い道</title><content type='html'>以前から疑問に思っていたSassのplaceholder selectorの使い道がひとつ見つかりました。それは既存の継承の定義を汚さずに拡張を行うというものでした。といっても例をあげないことにはぱっと伝わらないと思います。以下のような順番でおさらいをしながら話を進めます。&lt;br /&gt;
&lt;br /&gt;
extend =&gt; placeholder selector =&gt; codeschoolの応用問題&lt;br /&gt;
&lt;br /&gt;
&lt;style type=&#39;text/css&#39;&gt;
.left {
  width: 250px; 
  float: left; 
  background-color: #eee; 
  padding: 10px;
}

.arrow {
  float: left;
  padding: 100px 20px;
}

.right {
  width: 250px; 
  float: left; 
  background-color: #dde; 
  padding: 10px;
}
&lt;/style&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;@extendの基本的な使い方&lt;/h1&gt;&lt;br /&gt;
@extendの基本的な使い方はこのようにクラスを拡張して他の要素(この例だとborder-with)を付け足すことだ。&lt;br /&gt;
&lt;pre class=&#39;left&#39;&gt;.error {
  border: 1px #f00;
  background-color: #fdd;
}

.seriousError {
  @extend .error;
  border-width: 3px;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;arrow&#39;&gt;&gt;&gt; &lt;/div&gt;&lt;br /&gt;
&lt;pre class=&#39;right&#39;&gt;.error, .seriousError {
  border: 1px #f00;
  background-color: #fdd; }

.seriousError {
  border-width: 3px; }
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;clear&#39;&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
出力結果はもともと定義されていたCSS上の.error{} にセレクタである.seriousErrorを追加して同じスタイルを適応している。さらに.seriousError{ border-width: 3px; } を単体で宣言することで拡張という概念を実現している。&lt;br /&gt;
&lt;br /&gt;
では、上記の例のように既に.errorsが拡張されている場合に、.errorsを別のところでも定義したらどうなるだろうか？&lt;br /&gt;
&lt;pre class=&#39;left&#39;&gt;.error {
  border: 1px #f00;
  background-color: #fdd;
}
.error.intrusion {
  background-image: url(&quot;/image/hacked.png&quot;);
}
.seriousError {
  @extend .error;
  border-width: 3px;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;arrow&#39;&gt;&gt;&gt; &lt;/div&gt;&lt;br /&gt;
&lt;pre class=&#39;right&#39;&gt;.error, .seriousError {
  border: 1px #f00;
  background-color: #fdd; }

.error.intrusion, .seriousError.intrusion {
  background-image: url(&quot;/image/hacked.png&quot;); }

.seriousError {
  border-width: 3px; }
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;clear&#39;&gt;&lt;/div&gt;出力結果には.error.intrusion だけでなく.seriousError.intrusion もできるんですね。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
実はこれ&lt;a href=&#39;http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#how_it_works&#39;&gt;本家のリファレンス&lt;/a&gt;にある基本的なextendの例なんです。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;placeholder selector&lt;/h1&gt;&lt;br /&gt;
&lt;a href=&#39;http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#placeholders&#39;&gt;Placeholder selector&lt;/a&gt;はそれそのものの定義は何も出力されませんが、それをextendするとextendした先の定義が出力されます&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;left&#39;&gt;// This ruleset won&#39;t be rendered on its own.
#context a%extreme {
  color: blue;
  font-weight: bold;
  font-size: 2em;
}

//However, placeholder selectors can be extended, just like classes and ids. The extended selectors will be generated, but the base placeholder selector will not. For example:

.notice {
  @extend %extreme;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;arrow&#39;&gt;&gt;&gt; &lt;/div&gt;&lt;br /&gt;
&lt;pre class=&#39;right&#39;&gt;#context a.notice {
  color: blue;
  font-weight: bold;
  font-size: 2em; }
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;clear&#39;&gt;&lt;/div&gt;僕はこれの使い道がいまいち分かりませんでした。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Codeschool&lt;/h2&gt;&lt;br /&gt;
以下は僕がCodeschoolで遭遇した問題です。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= 問題本文 = &lt;br /&gt;
Whoops - we&#39;ve discovered an alteration to .blueprint later in our stylesheet, and extending .blueprint with .surveyor is creating extra selectors in .factory that aren&#39;t needed. Create a placeholder selector called container to hold the shared properties and extend it with .blueprint and .surveyor to remove the extra .factory .surveyor selector.&lt;br /&gt;
&lt;br /&gt;
？？？なんじゃそりゃ。と初見だと文の意味すらよく理解できなかったです。&lt;br /&gt;
でも上記のコンテキストを踏んでいるのでもうお分かりじゃないかと思います。&lt;br /&gt;
&lt;br /&gt;
意訳するとこういうことですね。&lt;br /&gt;
&lt;br /&gt;
最初に .blueprint を定義して .factoryでextendした。&lt;br /&gt;
&lt;pre class=&#39;left&#39;&gt;.blueprint {
  background: blue;
  border-radius: 5px;
  margin-bottom: 15px;
  padding: 10px;
}
.factory {
  background: #fff;
  .blueprint {
    margin-bottom: 20px;
  }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;clear&#39;&gt;&lt;/div&gt;&lt;br /&gt;
だけど、変更が必要で .surveyor を作って extend した。&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;left&#39;&gt;.blueprint {
  background: blue;
  border-radius: 5px;
  margin-bottom: 15px;
  padding: 10px;
}
.surveyor {
  @extend .blueprint;
  color: #fff;
}

.factory {
  background: #fff;
  .blueprint {
    margin-bottom: 20px;
  }
}
&lt;/pre&gt;&lt;div class=&#39;clear&#39;&gt;&lt;/div&gt;&lt;br /&gt;
そしたら、出力結果に予期せぬ余分な .factory .surveyor が入ったのでこれを取り除きたい。&lt;br /&gt;
&lt;pre class=&#39;left&#39;&gt;.blueprint, .surveyor {
  background: blue;
  border-radius: 5px;
  margin-bottom: 15px;
  padding: 10px;
}

.surveyor {
  color: #fff;
}

.factory {
  background: #fff;
}
.factory .blueprint, .factory .surveyor {
  margin-bottom: 20px;
}
&lt;/pre&gt;&lt;div class=&#39;clear&#39;&gt;&lt;/div&gt;&lt;br /&gt;
Placeholder selectorを作って余分な .factory .surveyorセレクタを削除してください。&lt;br /&gt;
&lt;br /&gt;
どうでしょう、make senseしましたか?すでに定義済みの継承関係.factory{ .blueprint{} }を汚さないように拡張をするのにplaceholder selector使ってくださいと言っています。こういうケースならplaceholder selectorが使えるのかもしれません。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
では以下が問題全文です。回答もありますので併せて参考にしてみてください。&lt;br /&gt;
&lt;br /&gt;
Whoops - we&#39;ve discovered an alteration to .blueprint later in our stylesheet, and extending .blueprint with .surveyor is creating extra selectors in .factory that aren&#39;t needed. Create a placeholder selector called container to hold the shared properties and extend it with .blueprint and .surveyor to remove the extra .factory .surveyor selector.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;left&#39;&gt;.blueprint {
  background: blue;
  border-radius: 5px;
  margin-bottom: 15px;
  padding: 10px;
}
.surveyor {
  @extend .blueprint;
  color: #fff;
}

.factory {
  background: #fff;
  .blueprint {
    margin-bottom: 20px;
  }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;arrow&#39;&gt;&gt;&gt; &lt;/div&gt;&lt;br /&gt;
&lt;pre class=&#39;right&#39;&gt;.blueprint, .surveyor {
  background: blue;
  border-radius: 5px;
  margin-bottom: 15px;
  padding: 10px;
}

.surveyor {
  color: #fff;
}

.factory {
  background: #fff;
}
.factory .blueprint, .factory .surveyor {
  margin-bottom: 20px;
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;clear&#39;&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
回答；&lt;br /&gt;
&lt;pre class=&#39;left&#39;&gt;%container {
  background: blue;
  border-radius: 5px;
  margin-bottom: 15px;
  padding: 10px;
}

.blueprint {
  @extend %container;
}
.surveyor {
  @extend %container;
  color: #fff;
}

.factory {
  background: #fff;
  .blueprint {
    margin-bottom: 20px;
  }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;arrow&#39;&gt;&gt;&gt; &lt;/div&gt;&lt;br /&gt;
&lt;pre class=&#39;right&#39;&gt;.blueprint, .surveyor {
  background: blue;
  border-radius: 5px;
  margin-bottom: 15px;
  padding: 10px; }

.surveyor {
  color: #fff; }

.factory {
  background: #fff; }

 .factory .blueprint {
   margin-bottom: 20px; }
&lt;/pre&gt;&lt;br /&gt;
&lt;div class=&#39;clear&#39;&gt;&lt;/div&gt;&lt;br /&gt;
まずは.blueprintに親になる %containerを定義して拡張することで出力結果の .blueprint{} と .factory .blueprint{} を実現します。.surveyor{} には color: #fff; という拡張を入れたいので別途 %containerをextendしています。そうすると、.factory { .blueprint{} } は .blueprint だけに適用されますから余分な .factory .surveyerは出力されません。&lt;br /&gt;
&lt;br /&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/7070521224594752265'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/7070521224594752265'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2013/01/sass-extendplaceholder-seloctor.html' title='[Sass] @extendの覚えておくべき動作とplaceholder seloctorの使い道'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-9066536181608494871</id><published>2013-01-07T05:43:00.001+00:00</published><updated>2013-01-07T05:46:06.048+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Git"/><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>CodeSchoolを試してみてる</title><content type='html'>最近いろいろなタイプのオンラインの学習サイトが乱立していることは皆さんもご存知のことと思います。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&#39;http://jp.techcrunch.com/archives/201208215-ways-to-learn-code-from-the-comfort-of-your-own-browser/&#39;&gt;お手軽にプログラミングを学習したい人のための厳選5サイト&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
その中にはあまりにも一般化しすぎているものや、”やりたいことはあるけど使い勝手がいまいち。。”的なものなどあって、試してみるまでなかなかどれが良いか分かりません。そんな中周りの評判が良かったのと、自分で使った感じも良かったので&lt;a href=&#39;http://www.codeschool.com/&#39;&gt;CodeSchool&lt;/a&gt;を使い始めています。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;コードスクールの良さ&lt;/h2&gt;&lt;br /&gt;
コードスクールが良いのは、書きながら覚えていくことにラーニングのアプリケーションが特化しているので知識の吸収効率が良いこと、それから、&lt;a href=&#39;http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html&#39;&gt;ながーーいリファレンス&lt;/a&gt;から必要な情報を抽出する手間を省いてくれていることなどです。&lt;br /&gt;
&lt;br /&gt;
Webのエンジニアリングの世界って分量的にカバーしておくべきが多いですよね？CodeSchoolは月＄５０と割高な感じなんですが、全ての技術に分厚い本を買って望む暇は無いけれど体系化した知識を付けてないと業務上の実践では不安というケースには有効です。&lt;br /&gt;
&lt;br /&gt;
コースは&lt;a href=&#39;http://www.codeschool.com/courses&#39;&gt;こんな感じ&lt;/a&gt;のがあります。今のところRuby on Rails界隈のスタックが多いけど、徐々に汎用的なコースが増えてきている感じがします。&lt;br /&gt;
&lt;br /&gt;
Git, Sass, CSS, Mobile, HTML5, Coffeescript, jQuery, iOSなんかのコースがあるのもうれしいですね。&lt;br /&gt;
- &lt;a href=&#39;http://www.codeschool.com/courses/tag/javascript&#39;&gt;Javascript&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&#39;http://www.codeschool.com/courses/tag/design&#39;&gt;デザイン&lt;/a&gt;&lt;br /&gt;
- &lt;a href=&#39;http://www.codeschool.com/courses/tag/webtools&#39;&gt;Web tools&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;始めた理由&lt;/h2&gt;&lt;br /&gt;
- 以前iKnowを毎日やって成果が出たので感覚的にこういう感じのタイプの公文式みたいに繰り返しやって覚えるオンラインラーニングに慣れている&lt;br /&gt;
- 毎日２時間の学習時間は取れないけど、３０分なら取れる。週に一日２時間よりも、毎日３０分x５日の方が頭に定着する&lt;br /&gt;
- ＄５０は高いけど本の料金やWeb上のドキュメントとそれにかける時間を考えるとまあ良いかなと思える。仕事への投資と思えば安い。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
迷っている人は全てのコースの１個目のチャレンジは無料なのでものの試しにやってみることをお勧めします。ユーザ登録しておくとたまにディスカウントのメールが来るので良いですよ。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
以上、また一ヶ月後に使った感想を書くかも！&lt;br /&gt;
&lt;br /&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/9066536181608494871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/9066536181608494871'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2013/01/codeschool.html' title='CodeSchoolを試してみてる'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-7498389159546171629</id><published>2012-12-25T03:23:00.000+00:00</published><updated>2012-12-25T03:23:41.567+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>lightwindowのHTMLを:js =&gt; trueなexampleで試験するのはwithin_frameが良いけどissues #365に遭遇した</title><content type='html'>Integration testを書いていたらlight windowの中にIframeでレンダリングされるHTML pageがあって、testにはCapybaraのwithin_frameが良いことを発見した。within_frameはSeleniumにも&lt;a href=&#39;http://www.rubydoc.info/gems/capybara-webkit/0.12.1/Capybara/Driver/Webkit#within_frame-instance_method&#39;&gt;Webkit&lt;/a&gt;にもある。&lt;br /&gt;
&lt;br /&gt;
ただし、lightwindowに親のURLを変えるようなjavascriptがありこの&lt;a href=&#39;https://github.com/thoughtbot/capybara-webkit/issues/365&#39;&gt;issue #365&lt;/a&gt;に遭遇してしまった。&lt;br /&gt;
&lt;br /&gt;
そもそもAjaxでリクエストした結果をIframeに描写するという実装は複雑すぎるしあんまりテストフレンドリーじゃないからやめたい。ということで結局は実装を変えることにした</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/7498389159546171629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/7498389159546171629'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/12/lightwindowhtmljs-trueexamplewithinfram.html' title='lightwindowのHTMLを:js =&gt; trueなexampleで試験するのはwithin_frameが良いけどissues #365に遭遇した'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-5239173979222159421</id><published>2012-09-12T16:45:00.002+01:00</published><updated>2012-09-12T16:53:02.932+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Rubyでインスタンスの属性にクラス内からメソッドを追加する</title><content type='html'>Stackoverflowで`Rubyでインスタンスの属性にメソッドを追加する`方法を聞いたら、ボヘミアの田舎町から&lt;a href=&quot;http://stackoverflow.com/questions/12383679/adding-a-method-to-an-attribute-in-ruby&quot;&gt;解答が付いた&lt;/a&gt;！&lt;br /&gt;
&lt;br /&gt;
題名が何いってるかわからんかもしれないのでどういうことか説明します。&lt;br /&gt;
ちょいちょいActiveRecord::Baseのattributeだけにメソッドを足してこういう風に書きたいことがあった。 &lt;br /&gt;
&lt;pre class=&#39;ruby&#39; name=&#39;code&#39;&gt;html_snippet = HtmlSnippet.find(1)
html_snippet.content = &quot;Link to http://stackoverflow.com&quot;
html_snippet.content.replace_url_to_anchor_tag!
# =&gt; &quot;Link to &lt;a href=&#39;http://stackoverflow.com&#39;&gt;http://stackoverflow.com&lt;/a&gt;&quot;
&lt;/pre&gt;&lt;br /&gt;
これを実現するのにそのクラス定義内にcontentにreplace_url_to_anchor_tag!を追加するメソッドを定義したかった。&lt;br /&gt;
&lt;br /&gt;
ActiveRecordのクラスはこんなかんじ&lt;br /&gt;
&lt;pre class=&#39;ruby&#39; name=&#39;code&#39;&gt;# app/models/html_snippet.rb
class HtmlSnippet &lt; ActiveRecord::Base    
  # I expected this bit to do what I want but not
  class &lt;&lt; @content
    def replace_url_to_anchor_tag!
      matching = self.match(/(https?:\/\/[\S]+)/)
      &quot;&lt;a href=&#39;#{matching[0]}&#39;/&gt;#{matching[0]}&lt;/a&gt;&quot;
    end
  end
end
&lt;/pre&gt;&lt;br /&gt;
↑あきらかにClass classの@content(常にnil)にメソッドを定義してるため動かない。&lt;br /&gt;
&lt;br /&gt;
1つの解；&lt;br /&gt;
頂いた回答によると、インスタンスメソッドの中で変数にメソッドを追加すればいい。ここでいうと`decorate_it`&lt;br /&gt;
&lt;pre class=&#39;ruby&#39; name=&#39;code&#39;&gt;class HtmlSnippet &lt; ActiveRecord::Base

  # getter is overrided to extend behaviour of freshly loaded values
  def content
    value = read_attribute(:content)
    decorate_it(value) unless value.respond_to?(:replace_url_to_anchor_tag)
    value
  end

  def content=(value)
    dup_value = value.dup
    decorate_it(dup_value)
    write_attribute(:content, dup_value)
  end

  private
  def decorate_it(value)
    class &lt;&lt; value
      def replace_url_to_anchor_tag
        # ...
      end
    end
  end
end
&lt;/pre&gt;
&lt;br /&gt;
なんかやりたいことに対してコーディング量がtoo muchじゃないかなとか思うんだけど、万が一もっと簡潔な方法があったら教えてください。&lt;br /&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5239173979222159421'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5239173979222159421'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/09/ruby.html' title='Rubyでインスタンスの属性にクラス内からメソッドを追加する'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-20968713072103515</id><published>2012-06-17T06:36:00.001+01:00</published><updated>2012-06-17T06:39:52.016+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>RSpecのequal, eql, eq, be の違い</title><content type='html'>RSeqでshould equalと書くべきかeqlと書くべきか、それともbeと書くべきか時々混乱するのでこの際覚えてしまおうと意味で何がちがうんだろうと見てみた。それによるとごく簡単にまとめると以下のような結果だった。&lt;br /&gt;
&lt;br /&gt;
二つの変数を比較するとき；&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;変数の値だけを比べる&lt;/li&gt;
&lt;b&gt;eql&lt;/b&gt;   &lt;b&gt;eq&lt;/b&gt;
&lt;li&gt;変数の値だけでなく、インスタンスのobject_idまで比べる&lt;/li&gt;
&lt;b&gt;equal&lt;/b&gt;   &lt;b&gt;be&lt;/b&gt; &lt;/ul&gt;と、ここまで覚えておけばSpec書くのに支障はない。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
もう少し掘り下げると、それぞれ以下のような仕組みになっている。&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;eql&lt;/h3&gt;&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/eql.rb&#39;&gt;Matcherの場所はここ&lt;/a&gt;。実際にはObject#eql?を呼んでいる。&lt;br /&gt;
&lt;br /&gt;
&gt; arr.eql? :a =&gt; 1, :b =&gt; 2&lt;br /&gt;
=&gt; true&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;equal&lt;/h3&gt;&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/equal.rb&#39;&gt;Matcherの場所はここ&lt;/a&gt;。実際にはObject#equal?を呼んでいる&lt;br /&gt;
&lt;br /&gt;
&gt; arr.equal? :a =&gt; 1, :b =&gt; 2&lt;br /&gt;
=&gt; false&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;eq&lt;/h3&gt;eqの定義は&lt;a href=&#39;http://stackoverflow.com/a/9797559/273182&#39;&gt;DSLの方&lt;/a&gt;にあるらしい。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;be&lt;/h3&gt;&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/be.rb#L236&#39;&gt;Matcherの定義はここ&lt;/a&gt;。beに引数があれば&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/be.rb#L187&#39;&gt;BeSameAs#matches?&lt;/a&gt;がshouldによって呼ばれる仕組みになっている。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
整理して実際に試してみよう。以下のようにString, Array, Fixnumの型のインスタンスについてそれぞれeq, eql, equal, beのマッチャでSpecを実施してみた。&lt;br /&gt;
&lt;br /&gt;
# ./tmp_spec.rb&lt;br /&gt;
&lt;pre name=&#39;code&#39; class=&#39;ruby&#39;&gt;require &#39;rspec&#39;

describe &#39;eq&#39; do
  it(&#39;should find two strings are equal&#39;) { &quot;&quot;.should eq &quot;&quot;}
  it(&#39;should find two Arrays are equal&#39;) { {:a =&gt; 1}.should eq :a =&gt; 1 }
  it(&#39;should find two Fixnums are equal&#39;) { 1.should eq 1 }
end

describe &#39;eql&#39; do
  it(&#39;should find two strings are equal&#39;) { &quot;&quot;.should eql &quot;&quot;}
  it(&#39;should find two Arrays are equal&#39;) { {:a =&gt; 1}.should eql :a =&gt; 1 }
  it(&#39;should find two Fixnums are equal&#39;) { 1.should eql 1 }
end

describe &#39;equal&#39; do
  it(&#39;should find two Strings are equal&#39;) { &quot;&quot;.should equal &quot;&quot;}
  it(&#39;should find two Arrays are equal&#39;) { {:a =&gt; 1}.should equal :a =&gt; 1 }
  it(&#39;should find two Fixnums are equal&#39;) { 1.should equal 1 }
end

describe &#39;be&#39; do
  it(&#39;should find two strings are equal&#39;) { &quot;&quot;.should be &quot;&quot;}
  it(&#39;hould find two Arrays are equal&#39;) { {:a =&gt; 1}.should be :a =&gt; 1 }
  it(&#39;should find two Fixnums are equal&#39;) { 1.should be 1 }
end
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
結果は以下のとおり。equalとbeでは　String, Arrayではobject_idまで同じかチェックしている。&lt;br /&gt;
&lt;pre name=&#39;code&#39; class=&#39;prettyprint&#39;&gt;$ rspec tmp_spec.rb -f doc

eq
  should find two strings are equal
  should find two Arrays are equal
  should find two Fixnums are equal

eql
  should find two strings are equal
  should find two Arrays are equal
  should find two Fixnums are equal

equal
  should find two Strings are equal (FAILED - 1)
  should find two Arrays are equal (FAILED - 2)
  should find two Fixnums are equal

be
  should find two strings are equal (FAILED - 3)
  hould find two Arrays are equal (FAILED - 4)
  should find two Fixnums are equal

Failures:

  1) equal should find two Strings are equal
     Failure/Error: it(&#39;should find two Strings are equal&#39;) { &quot;&quot;.should equal &quot;&quot;}
       
       expected #&lt;String:79962750&gt; =&gt; &quot;&quot;
            got #&lt;String:79962730&gt; =&gt; &quot;&quot;
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       &#39;actual.should == expected&#39; if you don&#39;t care about
       object identity in this example.
     # ./tmp_spec.rb:16:in `block (2 levels) in &lt;top (required)&gt;&#39;

  2) equal should find two Arrays are equal
     Failure/Error: it(&#39;should find two Arrays are equal&#39;) { {:a =&gt; 1}.should equal :a =&gt; 1 }
       
       expected #&lt;Hash:79945050&gt; =&gt; {:a=&gt;1}
            got #&lt;Hash:79945060&gt; =&gt; {:a=&gt;1}
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       &#39;actual.should == expected&#39; if you don&#39;t care about
       object identity in this example.
       
       
       Diff:{:a=&gt;1}.==({:a=&gt;1}) returned false even though the diff between {:a=&gt;1} and {:a=&gt;1} is empty. Check the implementation of {:a=&gt;1}.==.
     # ./tmp_spec.rb:17:in `block (2 levels) in &lt;top (required)&gt;&#39;

  3) be should find two strings are equal
     Failure/Error: it(&#39;should find two strings are equal&#39;) { &quot;&quot;.should be &quot;&quot;}
       
       expected #&lt;String:79934250&gt; =&gt; &quot;&quot;
            got #&lt;String:79934260&gt; =&gt; &quot;&quot;
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       &#39;actual.should == expected&#39; if you don&#39;t care about
       object identity in this example.
     # ./tmp_spec.rb:22:in `block (2 levels) in &lt;top (required)&gt;&#39;

  4) be hould find two Arrays are equal
     Failure/Error: it(&#39;hould find two Arrays are equal&#39;) { {:a =&gt; 1}.should be :a =&gt; 1 }
       
       expected #&lt;Hash:79932410&gt; =&gt; {:a=&gt;1}
            got #&lt;Hash:79932420&gt; =&gt; {:a=&gt;1}
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       &#39;actual.should == expected&#39; if you don&#39;t care about
       object identity in this example.
       
       
       Diff:{:a=&gt;1}.==({:a=&gt;1}) returned false even though the diff between {:a=&gt;1} and {:a=&gt;1} is empty. Check the implementation of {:a=&gt;1}.==.
     # ./tmp_spec.rb:23:in `block (2 levels) in &lt;top (required)&gt;&#39;

Finished in 0.01339 seconds
12 examples, 4 failures

Failed examples:

rspec ./tmp_spec.rb:16 # equal should find two Strings are equal
rspec ./tmp_spec.rb:17 # equal should find two Arrays are equal
rspec ./tmp_spec.rb:22 # be should find two strings are equal
rspec ./tmp_spec.rb:23 # be hould find two Arrays are equal
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
でもこのFixnumの比較に関しては Specが成功してしまう。&lt;br /&gt;
&lt;pre name=&#39;code&#39; class=&#39;ruby&#39;&gt;describe &#39;be&#39; do
  it(&#39;should find two Fixnums are equal&#39;) { 1.should be 1 }
end
&lt;/pre&gt;&lt;br /&gt;
これはFixnumのidがrubyを起動時に実行されて既に予約済みだからのようだ&lt;br /&gt;
&lt;br /&gt;
irb/ pry&lt;br /&gt;
&lt;pre name=&#39;code&#39; class=&#39;ruby&#39;&gt;[28] pry(main)&gt; 1.object_id
=&gt; 3
[29] pry(main)&gt; 2.object_id
=&gt; 5
[30] pry(main)&gt; 3.object_id
=&gt; 7
[35] pry(main)&gt; 1.object_id
=&gt; 3


[32] pry(main)&gt; 1.0.object_id
=&gt; 105431370
&lt;/pre&gt;&lt;br /&gt;
このようにFixnumのインスタンスはシングルトンで定義されているようだ。</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/20968713072103515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/20968713072103515'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/06/rspecequal-eql-eq-be.html' title='RSpecのequal, eql, eq, be の違い'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-2190232452706505948</id><published>2012-06-15T10:06:00.002+01:00</published><updated>2012-06-15T10:07:53.182+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>ひとりごと on RSpec</title><content type='html'>ああ　かれこれ１時間くらい CapybaraのRSpec上でActioveRecord::Baseなクラスの値がchangeしないパターンにはまってた。&lt;br /&gt;
&lt;br /&gt;
こんな場合；&lt;br /&gt;
ユーザのパスワードリセッタを実装するときにone_time_tokenを発行してメールを送信する。メール中のtokenとデータベイスに保存されたtokenが一緒かチェック。同じだったら、パスワードを再設定する画面に進む。他にもセキュリティを守るための処理はあるけど基本的な処理はそんなかんじ。&lt;br /&gt;
&lt;br /&gt;
Specはこんな感じ&lt;br /&gt;
&lt;pre name=&#39;code&#39; class=&#39;ruby&#39;&gt;let(:user) { User.make } # =&gt; machinist/acive_record

 it &quot;user&#39;s token should be updated&quot; do
  expect{ click_button &#39;メール送信&#39; }.to change{ user.one_time_token }
end

expect{ click_button &#39;メール送信&#39;; user.reload }.to change{ user.one_time_token }
# =&gt; Got: one_time_token is still &quot;&quot;
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
正しくはuser.reloadを追加しないといけない。&lt;br /&gt;
&lt;pre name=&#39;code&#39; class=&#39;ruby&#39;&gt;it &quot;user&#39;s token should be updated&quot; do
  expect{ click_button &#39;メール送信&#39;; user.reload }.to change{ user.one_time_token }
end
&lt;/pre&gt;&lt;br /&gt;
changeの中は遅延評価されたuser を参照しているからRSpecの空間で故意にreloadしないと one_time_tokenがActiveRecord上では変わらない。普通の人はすぐ気づくのかなあ？</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/2190232452706505948'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/2190232452706505948'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/06/on-rspec.html' title='ひとりごと on RSpec'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-475248776092468509</id><published>2012-06-10T08:16:00.000+01:00</published><updated>2012-06-10T08:17:18.257+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Rubyに優しいキーバインディングのセッティング</title><content type='html'>Linuxで &#39;-&#39;と&#39;_&#39;、&#39;:&#39;と&#39;;&#39;をスワップしておくとコード書くとき便利です。&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&#39;shell&#39; name=&#39;code&#39;&gt;# ~/.bashrc

# Key bindings
xmodmap -e &#39;keycode 47 = colon semicolon&#39;
xmodmap -e &#39;keycode 20 = underscore minus underscore minus backslash questiondown&#39;
&lt;/pre&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/475248776092468509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/475248776092468509'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/06/ruby.html' title='Rubyに優しいキーバインディングのセッティング'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-2740206096405086535</id><published>2012-06-04T17:06:00.003+01:00</published><updated>2012-06-04T17:29:54.214+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>RSpecのshouldは何をしてるの？　RSpecの仕組み</title><content type='html'>RSpecのshouldはどうやって動いているのか？..という仕組みについてpaperboy&amp;co.の方が既にcodeを読んで解説されているスライドを見つけました。&lt;br /&gt;
&lt;br /&gt;
まずshouldが全てのinstaceで実効可能なのは&lt;a href=&#39;http://banyan.github.com/slides/20120321/#/step-12&#39;&gt;Kernel classに対して定義されている&lt;/a&gt;からです。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/expectations/extensions/kernel.rb#L26&#39;&gt;shouldの居場所&lt;/a&gt;&lt;br /&gt;
&lt;pre class=&#39;ruby&#39; name=&#39;code&#39;&gt;# spec/expectations/extensions/kernel.rb
def should(matcher=nil, message=nil, &amp;block)
  Spec::Expectations::PositiveExpectationHandler.handle_matcher(self, matcher, message, &amp;block)
end
&lt;/pre&gt;&lt;br /&gt;
&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/expectations/handler.rb#L5&#39;&gt;PositiveExpectationHandler#handle_matcherの居場所&lt;/a&gt;&lt;br /&gt;
&lt;pre class=&#39;ruby&#39; name=&#39;code&#39;&gt;# spec/expectations/handler.rb
match = matcher.matches?(actual, &amp;block)
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;&lt;a href=&#39;http://banyan.github.com/slides/20120321/#/step-9&#39;&gt;RSpecの構造&lt;/a&gt;&lt;/h3&gt;&lt;pre&gt;/lib
└── spec
    ├── expectations
    │   └── extensions
    └── matchers
        └── extensions
&lt;/pre&gt;&lt;br /&gt;
expectations/extensionsはその名のとおり拡張を行う。&lt;a href=&#39;https://github.com/dchelimsky/rspec/tree/master/lib/spec/expectations/extensions&#39;&gt;spec/expectations/extensions/にはkernel.rbのみがある&lt;/a&gt;。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&#39;http://banyan.github.com/slides/20120321/#/step-9&#39;&gt;RSpecの構造&lt;/a&gt;&lt;br /&gt;
&lt;a href=&#39;https://github.com/dchelimsky/rspec/tree/master/lib/spec/matchers&#39;&gt;spec/matchers&lt;/a&gt;には見慣れた名前が。。&lt;br /&gt;
&lt;br /&gt;
ずっとshouldはきっと variable.be_a Stringてかくと variable.is_a? Stringって変えてくれると想像して信じていたけど、実際の条件は逐一Matcherに書いてあるらしい。例えば&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/be_kind_of.rb&#39;&gt;be_kind_of matcher&lt;/a&gt;&lt;br /&gt;
&lt;pre class=&#39;ruby&#39; name=&#39;code&#39;&gt;def be_a_kind_of(expected)
  Matcher.new :be_a_kind_of, expected do |_expected_|
    match do |actual|
      actual.kind_of?(_expected_)
    end
  end
end
&lt;/pre&gt;&lt;br /&gt;
be Matcherには&lt;a href=&#39;http://banyan.github.com/slides/20120321/#/step-31&#39;&gt;僕が想像していたような機能がある&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
§&lt;br /&gt;
&lt;br /&gt;
Matcherを自作したい時は Object.should be_fine =&gt; Object.fine?の法則に当てはまるfine? methodを持つObject定義してあげるか、matches?にrespondするMatcherを書いて&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers.rb&#39;&gt;matcher.rb&lt;/a&gt;みたいに requireしてあげればいいはず。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
§&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;蛇足だけど&lt;/h3&gt;上記 kernel.rbのとおり&lt;a href=&#39;http://kerryb.github.com/iprug-rspec-presentation/#34&#39;&gt;引数にmessageを渡してfailure時に何が失敗したのかわかりやすくすることもできる&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
別のshould、&lt;a href=&#39;https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/subject.rb#L62&#39;&gt;Subject#shouldの居場所&lt;/a&gt;&lt;br /&gt;
これは以下の用に書いたときのshouldにちがいない（と信じてる）&lt;br /&gt;
&lt;pre name=&#39;code&#39; class=&#39;ruby&#39;&gt;let(:int) { 16 }
subject { int }

it &quot;should be even&quot; do
  should be_even
end
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Change&lt;/h3&gt;例えばこんな感じに書いたときは&lt;br /&gt;
&lt;pre&gt;expect{ array &lt;&lt; 42 }.to change{ array.size }.from(0).to(1)
&lt;/pre&gt;
&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/change.rb#L4&#39;&gt;initializeで @value_proc に{ array &lt;&lt; 42 }が代入されて&lt;/a&gt;、&lt;a href=&#39;https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/change.rb#L78&#39;&gt;from methodで@fromに0が、to methodで@to に1が代入される。&lt;/a&gt;比較は他のmatchers同様&lt;a href=https://github.com/dchelimsky/rspec/blob/master/lib/spec/matchers/change.rb#L11&gt;matches?&lt;/a&gt;で @beforeと@afterを比較して行われる。event_procには array.sizeが代入される。

&lt;pre class=&#39;ruby&#39; name=&#39;code&#39;&gt;@before = evaluate_value_proc
event_proc.call
@after = evaluate_value_proc
&lt;/pre&gt;&lt;a href=&#39;http://banyan.github.com/slides/20120321/#/step-4&#39;&gt;スライド&lt;/a&gt;すばらしいので全部読むべし&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/2740206096405086535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/2740206096405086535'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/06/rspecshould.html' title='RSpecのshouldは何をしてるの？　RSpecの仕組み'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-2435368128232634934</id><published>2012-05-30T14:54:00.002+01:00</published><updated>2012-05-30T14:58:02.254+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'></title><content type='html'>最近なんかマイクロブログみたいになってるけど。。&lt;br /&gt;
RailsがIf-None-Match headerを公式にサポートしているのを発見。実際に使われているプロジェクトに出会ったことはない。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&#39;http://guides.rubyonrails.org/caching_with_rails.html#conditional-get-support&#39; &gt;Rails Guide: Conditional GET support&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Ajax requestなんかでresponseが空だった場合は画面に対して何もしない。キャッシュも返さないからサーバ側の負担を軽減する。とかいうのが使いどころなのかな。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&#39;http://odino.org/don-t-rape-http-if-none-match-the-412-http-status-code/&#39;&gt;If_None_Match headerについての解説記事&lt;/a&gt;&lt;br /&gt;
If-None-Matchに仕込んであるEtagが更新されテイルかチェックするためには&lt;a href=&#39;http://apidock.com/rails/ActionController/ConditionalGet/stale%3F&#39;&gt;ActionController#stale?&lt;/a&gt;を使う&lt;br /&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/2435368128232634934'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/2435368128232634934'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/05/railsif-none-match-header-httpguides.html' title=''/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-6687023219528263886</id><published>2012-05-23T14:48:00.002+01:00</published><updated>2012-05-24T01:31:35.665+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>RSpec evidence with progress bar</title><content type='html'>Just found that &#39;rspec&#39; takes multiple options to specify formats like I do in the following snippet.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2p_LUSV2wPlXCVDi_Pnm0j4z7bufups2gei44BOuIlIOChdVd2SOxtVFRWrK66pbRx9XQOYetC1-Vyws06EWnoeNaqw-2HeyUJ15mTzm8FvtPHFxg6lKUxL4XMuJbwgYg-Swf8uUqfGlh/s1600/rspec.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left:1em; margin-right:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;125&quot; width=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2p_LUSV2wPlXCVDi_Pnm0j4z7bufups2gei44BOuIlIOChdVd2SOxtVFRWrK66pbRx9XQOYetC1-Vyws06EWnoeNaqw-2HeyUJ15mTzm8FvtPHFxg6lKUxL4XMuJbwgYg-Swf8uUqfGlh/s400/rspec.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&#39;-f Fuubar&#39; to show a progress bar.  &lt;br /&gt;
I do test all specs of thousands in a project I&#39;m currently working on. So, better have a progress bar. &lt;br /&gt;
&lt;br /&gt;
&#39;-f doc&#39; to generate sentences according to  specs. &lt;br /&gt;
I use methods &#39;let&#39;, &#39;subject&#39;, &#39;shared_examples_for&#39; make output of &#39;rspec&#39; self-explanatory.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/6687023219528263886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/6687023219528263886'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/05/rspec-evidence-with-progress-bar.html' title='RSpec evidence with progress bar'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2p_LUSV2wPlXCVDi_Pnm0j4z7bufups2gei44BOuIlIOChdVd2SOxtVFRWrK66pbRx9XQOYetC1-Vyws06EWnoeNaqw-2HeyUJ15mTzm8FvtPHFxg6lKUxL4XMuJbwgYg-Swf8uUqfGlh/s72-c/rspec.png" height="72" width="72"/></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-5346108572038673050</id><published>2012-05-22T14:50:00.000+01:00</published><updated>2012-05-28T08:52:48.324+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>TextMateでハイフンとアンダーラインを変更する</title><content type='html'>Mac初心者の私ですが、会社でMacBook Proを与えられたのでちょっとずつ自分仕様にしていくつもりです。&lt;br /&gt;
&lt;br /&gt;
今日はTextmateでハイフンとアンダーラインを交換する方法です。今日の設定はCoccoaを使っているアプリに有効みたいだけど、TextMate、Emacsあたり意外でどのアプリに有効になるかは今のとこわからないです。&lt;br /&gt;
&lt;br /&gt;
&lt;pre &gt;$ vim ~/Library/KeyBindings/DefaultKeyBinding.dict
{
  /* &quot;変更元&quot; = (&quot;命令&quot;, &quot;値&quot;);  */
  &quot;-&quot; = (&quot;insertText:&quot;, &quot;_&quot;);
  &quot;$_&quot; = (&quot;insertText:&quot;, &quot;-&quot;);
  &quot;;&quot; = (&quot;insertText:&quot;, &quot;:&quot;);
  &quot;$:&quot; = (&quot;insertText:&quot;, &quot;;&quot;);
}
&lt;/pre&gt;&lt;br /&gt;
ちなみに英語ではハイフンはdash、アンダーラインはunderscoreと一般的に呼ばれています。&lt;br /&gt;
&lt;br /&gt;
参考:&lt;br /&gt;
&lt;a href=&#39;http://blog.macromates.com/2005/key-bindings-for-switchers/&#39;&gt;http://blog.macromates.com/2005/key-bindings-for-switchers/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&#39;http://xahlee.org/emacs/osx_keybinding_key_syntax.html&#39;&gt;http://xahlee.org/emacs/osx_keybinding_key_syntax.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
どういうコマンドがあるかは&lt;a href=&#39;http://www.hcs.harvard.edu/~jrus/Site/selectors.html&#39;&gt;ここ&lt;/a&gt;を参考にしてください。</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5346108572038673050'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5346108572038673050'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/05/textmate.html' title='TextMateでハイフンとアンダーラインを変更する'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-740139147285339400</id><published>2012-04-27T05:42:00.003+01:00</published><updated>2012-04-27T05:42:39.782+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Accessing ActionView::Base in a ActionController in Rails 2.3</title><content type='html'>just came accross an instance variable of an ActionView::Base in ActionController, which is @template;

&lt;pre class=&#39;ruby&#39; name=&#39;code&#39; &gt;
class AnyController &lt; ApplicationController
  def index
    logger.debug @template.inspect #=&gt; #&lt;ActionView::Base:0xb685da48 ..&gt;
  end
end
&lt;/pre&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/740139147285339400'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/740139147285339400'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/04/accessing-actionviewbase-in.html' title='Accessing ActionView::Base in a ActionController in Rails 2.3'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-7101700334507754620</id><published>2012-04-22T11:51:00.000+01:00</published><updated>2012-05-23T15:00:51.944+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Note: How to show SQL in Rails Console</title><content type='html'>Just add the following lines into&amp;nbsp;&amp;nbsp;config/environment.rb. This switches default logger to STDOUT.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;ruby&quot; name=&#39;code&#39;&gt;# Render SQL in Rails Console
if &quot;irb&quot; == $0
&amp;nbsp; require &#39;logger&#39;
&amp;nbsp; if ENV.include?(&#39;RAILS_ENV&#39;)&amp;amp;&amp;amp;
&amp;nbsp; !Object.const_defined?(&#39;RAILS_DEFAULT_LOGGER&#39;)
&amp;nbsp; &amp;nbsp; &amp;nbsp;Object.const_set(&#39;RAILS_DEFAULT_LOGGER&#39;, Logger.new(STDOUT))
&amp;nbsp; else
&amp;nbsp; &amp;nbsp; &amp;nbsp;ActiveRecord::Base.logger = Logger.new(STDOUT)
&amp;nbsp; end
end
&lt;/pre&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/7101700334507754620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/7101700334507754620'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2012/04/note-how-to-show-sql-in-rails-console.html' title='Note: How to show SQL in Rails Console'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-8298324680507938005</id><published>2012-04-08T04:45:00.000+01:00</published><updated>2012-04-09T07:35:34.482+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>script/consoleでhelper, routing</title><content type='html'>- 下記に追記&lt;br /&gt;
いつのバージョンからか(少なくとも2.3.14からは)名前付きルートはscript/consoleを立ち上げた時点でlink_to はhelperというActionView::Baseのインスタンスからアクセスできて、ダイナミックルートはappというActionController::Integration::Sessionのインスタンスからアクセスできるようになっていました。&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://blog.p.latyp.us/2008/03/calling-helpers-in-rails-console.html&quot;&gt;http://blog.p.latyp.us/2008/03/calling-helpers-in-rails-console.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--------------------------------&lt;br /&gt;
- コンソールで名前付きルート&lt;br /&gt;
&lt;a href=&quot;http://stuartsierra.com/2008/01/08/testing-named-routes-in-the-rails-console&quot;&gt;Testing Named Routes in the Rails Console&lt;/a&gt;からまんま拝借。&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;ruby&quot; name=&quot;code&quot;&gt;include ActionController::UrlWriter 
default_url_options[:host] = &#39;whatever&#39;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
default_url_optionsは名前のとおり、/parent_controller/:host/child_controller/:idといった定義に対して以下の用にコンソールで名前付きパスのデフォルトのオプションを指定してくれる。&lt;br /&gt;
action_controller_path(:id =&amp;gt; 23)&lt;br /&gt;
=&amp;gt; &quot;/parent_controller/watever/child_controller/23&quot;&lt;br /&gt;
belong_toなんかでリソースがネストしてる時に便利。&lt;br /&gt;
&lt;br /&gt;
rs = ActionController::Routing::Routes&lt;br /&gt;
rs.recognize_path action_controller_path(:id =&amp;gt; 23), :method =&amp;gt; &#39;GET&#39;&lt;br /&gt;
とかで、params =&amp;gt; {:host =&amp;gt; &#39;whatever&#39;, :id =&amp;gt; &#39;23&#39;}とかがパラメータとして渡ってくるはず。試してない。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- Helperをコンソールで&lt;br /&gt;
&lt;pre class=&quot;ruby&quot; name=&quot;code&quot;&gt;  include HelperYouWantToRun #使いたいhelperをincludeする。
  helper.method_you_want_to_run&lt;/pre&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/8298324680507938005'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/8298324680507938005'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2010/08/scriptconsolehelper-routing.html' title='script/consoleでhelper, routing'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-2234179213774522469</id><published>2011-12-27T15:46:00.001+00:00</published><updated>2012-01-03T18:14:41.456+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Linux"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Postfix + Rails on Ubuntu</title><content type='html'>&amp;nbsp;Luckily or unluckily, I hadn&#39;t had to work with ActionMailer to send emails via Postfix till this time&#39;s setting hell. Because, applications I wrote to send emails from my gmail account was as-needed basis and, alternatively, I just could leave the process to send emails to Amazon SES.&lt;br/&gt;
&lt;br/&gt;
&amp;nbsp;This time, an app I&#39;m currently working on reached the maximum limit of number of emails sent by logging-in Google&#39;s SMTP, which was 1000 out-going mails a day with my account of Google Apps for free, and I adopted using SMTP server set up in a VPS. I looked for a summarised article on this but couldn&#39;t find nice one, really.&lt;br/&gt;
&lt;br/&gt;
&amp;nbsp;I initially tried to get ActionMailer communicate with Qmail before Postfix. It did&#39;t work at all perhaps because it speaks slightly different SMTP apart from that of Sendmail and Postfix. So, I used combination of &lt;b&gt; Postfix + Rails on Ubuntu &lt;/b&gt; and relayed mails to Gmail&#39;s SMTPs.
&lt;br/&gt;
&lt;br/&gt;
&lt;h1&gt;My Environment&lt;/h1&gt;
&lt;pre class=prettyprint&gt;
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=lucid
DISTRIB_DESCRIPTION=&quot;Ubuntu 10.04.3 LTS&quot;

$ ruby --version
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]

$ gem list action
*** LOCAL GEMS ***
actionmailer (3.0.0)
&lt;/pre&gt;


&lt;h1&gt;Installing Postfix&lt;/h1&gt;
&amp;nbsp;There were two way to install binary version of Postfix with aptitude. One is to remove MTA currently installed, which forces you to install another MTA, and the other one is vice versa.&lt;br/&gt;
&lt;br/&gt;

So, usual this one line is fine.&lt;br/&gt;
&lt;pre&gt;
$ sudo aptitude install postfix&lt;br/&gt;
&lt;/pre&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;h1&gt;Setting up Postfix&lt;/h1&gt;
&lt;pre&gt;
 &lt;b&gt;Rails&lt;/b&gt; ==plain SMTP==&gt; &lt;b&gt;Postfix&lt;/b&gt; ==SMTP with TLS==&gt; &lt;b&gt;Gmail&#39;s SMTP server&lt;/b&gt;
&lt;/pre&gt;
&lt;br/&gt;
&amp;nbsp;Rails is able to communicates with Postfix without any unnecessary internal authentications in a box. Just set &lt;i&gt; smtpd_use_tls=no&lt;/i&gt; in /etc/postfix/main.cf. It apparently forces other smtpd_tls_* options ineffective. I didn&#39;t get any difference when I commented out the other smtpd options.&lt;br/&gt;
&lt;br/&gt;
&amp;nbsp;Make sure your setting of &lt;i&gt;mynetworks&lt;/i&gt; thoroughly shuts out SMTP server/client from outside. You could check it by using telnet I will mention later.
&lt;br/&gt;
&amp;nbsp;Let&#39;s reload to apply the setting.&lt;br/&gt;
&lt;pre class=prettyprint&gt;
$ sudo /etc/init.d/postfix reload
&lt;/pre&gt;
&lt;br/&gt;
&amp;nbsp;Let&#39;s telnet to list your setting and check if TLS is not working.&lt;br/&gt;
&lt;pre class=&#39;prettyprint&#39;&gt;
$ telnet localhost 25
 :
EHLO localhost # =&gt; type this command
250-www24085u.sakura.ne.jp
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN # =&gt; make sure you haven&#39;t got a line &#39;250-STARTTLS&#39;

STARTTLS # =&gt; this command tells you if TLS is implemented
502 5.5.1 Error: command not implemented
&lt;/pre&gt;
&lt;br/&gt;
You could use Telnet to check if your SMTP doesn&#39;t accept requests from outside&lt;br/&gt;
&lt;pre class=prettyprint&gt;
YourLocalBox$ telnet your.domain.com 25
&lt;/pre&gt;
&lt;br/&gt;
&lt;br/&gt;
&amp;nbsp;Now that your Postfix is ready to receive internal SMTP requests, let&#39;s move on to other options. It still doesn&#39;t send out emails because we haven&#39;t set up from who we send emails and to which SMTP server we relay emails.

&lt;pre class=prettyprint name=code&gt;
Add the following line to specify your domain name in email address. For instance, set &lt;i&gt;your.domain.com&lt;/i&gt; of &lt;i&gt;notification@your.domain.com&lt;/i&gt;
$ sudo vim /etc/mailname
your.domain.com

$ sudo vim /etc/postfix/sasl/passwd
[smtp.gmail.com]:587    &lt;i&gt;notification@your.domain.com:password&lt;/i&gt; # *0

$ sudo vim /etc/postfix/main.cf
myorigin = /etc/mailname
myhostname = www24085u.sakura.ne.jp # =&gt; *1

# Relay to Gmail
#relayhost = [smtp.gmail.com]:587 # =&gt; *2
smtp_use_tls = yes # =&gt; *3
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd
smtp_sasl_tls_security_options = noanonymous

&lt;/pre&gt;
&lt;br/&gt;
*0. Make sure you set email address and password of your gmail account that you want to use as a sender. Also, note that &lt;b&gt;Gmail&#39;s SMTP servers overwrite email address of a sender with this setting&lt;/b&gt;. It&#39;s MTS&#39;s right to do that.&lt;br/&gt;
&lt;br/&gt;
*1. This is an option to set your host name in the case where you actually send email from another domain but set &lt;b&gt;From&lt;/b&gt; in SMTP header email address you&#39;d like to spoof (legitimately). I sent email with From header &#39;notification@emailsan.com&#39; and Postfix was situated at www24085u.sakura.ne.jp. Thus, I set www24085u.sakura.ne.jp.&lt;br/&gt;
&lt;br/&gt;
*2. I first set the option to relay mails but bumped a maximum limit of relaying for one SMTP server during load test.&lt;br/&gt;
&lt;br/&gt;
*3. Postfix as a SMTP client need to use TLS to access Gmail&#39;s SMTP server. I&#39;m not quite sure but SASL needs TLS to complete its functions&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
Reload or restart Postfix again.
&lt;br/&gt;
&lt;br/&gt;
&lt;h1&gt;Setting up Rails&lt;/h1&gt;
In config/application.rb
&lt;pre class=ruby name=code&gt;
# SMTP SETTING FOR local Postfix without any authorisation
ActionMailer::Base.smtp_settings = {
  :address              =&gt; &quot;127.0.0.1&quot;,
  :port                 =&gt; 25, # =&gt; *1
  :domain               =&gt; &#39;your.hostname.com&#39;, # =&gt; *2
#  :user_name            =&gt; &#39;notification@your.domain.com,
#  :password             =&gt; &#39;password&#39;,
#  :authentication       =&gt; &#39;plain&#39;,
#  :tls   =&gt; true,
#  :openssl_verify_mode  =&gt; &#39;none&#39;,
  :enable_starttls_auto =&gt; false
}
&lt;/pre&gt;
&lt;br/&gt;
*1. Don&#39;t need to use submission port, 587, because we just set Postfix to talk without any auth and encryption within a box.&lt;br/&gt;
&lt;br/&gt;
*2. This must be the hostname where your rails app and Postfix is located &lt;br/&gt;
&lt;br/&gt;
*. Do not add any of the lines commented out, which can cause ActionMailer&#39;s attempting SMTP Authentication. It looked like Actionmailer doesn&#39;t EHLO to determine either which protocol to talk nor which authentication method to use. &lt;i&gt;&quot;tail  -f /var/log/mail.log&quot;&lt;/i&gt; may give you line something like this if it&#39;s the case;&lt;br/&gt;
&lt;pre class=prettyprint&gt;
postfix/smtpd[4032]: lost connection after AUTH from your.hostname.com[&lt;i&gt;ipaddress&lt;/i&gt;]
&lt;/pre&gt;

app/mailers/mailer_api.rb
&lt;pre class=ruby name=code&gt;
# encoding: UTF-8

class MailerApi &lt; ActionMailer::Base
  default :from =&gt; &#39;&quot;E mail-san&quot; &amp;lt;notification@emailsan.com&amp;gt&#39;, &lt;b&gt;:parts_order  =&gt; [&quot;text/plain&quot;, &quot;text/html&quot;]&lt;/b&gt; # =&gt; *1
    
  def compose to, subject, body_html, body_text
    @body_html = body_html
    @body_text = body_text
    mail :to =&gt; to, :subject =&gt; subject do |format|
      format.text # =&gt; *2
      format.html
    end
  end
  
end
&lt;/pre&gt;
*1. :parts_order specifies which part comes first. This matters when the mail you sent is bounced and, as a result,  makes different which part to be shown in bounced email.&lt;br/&gt;
&lt;br/&gt;
*2. It&#39;d be better send multi-part mail if thinking of handling body of bounced mail, which is MIME-enveloped. Giving two line, format.text and format.html respectively, makes ActionMailer send multi parted mail.&lt;br/&gt;
&lt;br/&gt;
To deliver an email;
&lt;pre class=ruby name=code&gt;
MailerApi.compose(to, subject, body_html, body_text).deliver
&lt;/pre&gt;
&amp;nbsp;It&#39;s my assumption that my Postfix looks for which smtp to use with query to DNS and relay email to one of them. Befause I initially used &#39;relay=&#39; option in main.cf and bumped limit. Then, comment out that line and grepping mail.log told me it still relays but various SMTP servers of Gmail. &lt;br/&gt;
&lt;pre&gt;
Dec 28 01:50:12 www24085u postfix/smtp[11638]: 855E6A19A0: to=&lt;szkmp@emailsan.com&gt;, orig_to=&lt;szkmp&gt;, relay=ASPMX.L.GOOGLE.com[74.125.53.26]:25, delay=10, delays=8.5/0.06/0.83/0.96, dsn=2.0.0, status=sent (250 2.0.0 OK 1325004612 l10si14011188pbj.164)
&lt;/pre&gt;
&lt;br/&gt;
FYI, here&#39;s my MX record;
&lt;pre&gt;
 MX  1 ASPMX.L.GOOGLE.COM. (TTL:300)
 MX  5 ALT1.ASPMX.L.GOOGLE.COM. (TTL:300)
 MX  5 ALT2.ASPMX.L.GOOGLE.COM. (TTL:300)
 MX  10 ASPMX2.GOOGLEMAIL.COM. (TTL:300)
 MX  10 ASPMX3.GOOGLEMAIL.COM. (TTL:300)

&lt;/pre&gt;


&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;h1&gt; How to inspect&lt;/h1&gt;
- Use telnet. It may tell you which step of communication is breaking down. e.g. Communication between Rails and Postfix or Postfix and Gmail&#39;s SMTP server. Trying SMTP Auth but failed. and so on..&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
- Set log level of main.cf the highest, 4;
&lt;i&gt;smtp_tls_loglevel=4&lt;/i&gt;
And tailing log files may give you details.&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
- Adding config.action_mailer.raise_delivery_errors = true to your development.rb or application.rb might give you useful information.
&lt;br/&gt;
&lt;br/&gt;
&lt;h1&gt;Verifying your domain&lt;/h1&gt;
So, you can now send email with your Postfix. If you will send bulk of emails, you need to verify your domain in ideally two ways, which are SPF and DKIM, to prevent your account from being blocked by other MTAs.

&lt;h2&gt;SPF&lt;/h2&gt;
Set SPF record into your DNS. In my case of application, I use 49.212.10.123 as a physical mail sender. And, send emails with it&#39;s From header &#39;notification@emailsan.com&#39;. So, the record is ;&lt;br/&gt;
&lt;pre&gt;
emailsan.com IN TXT  &quot;v=spf1 ip4:49.212.10.123 include:aspmx.googlemail.com ~all&quot;
&lt;/pre&gt;
You could nslookup if you want to;
&lt;pre&gt;
$ nslookup -q=txt emailsan.com
&lt;/pre&gt;
&lt;br/&gt;
&lt;br/&gt;
You could check the results by clicking &#39;show original&#39; button in just right adjacent the curving arrow in conversation pane in a new UI (as of Dec 2011) of Gmail. Below is side by side comparison of the before and after.&lt;br/&gt;
&lt;br/&gt;
Before;
&lt;pre&gt;
Authentication-Results: mx.google.com; spf=neutral (google.com: domain of notification@emailsan.com is neither permitted nor denied by best guess record for domain of example@cloudrop.jp)
&lt;/pre&gt;
&lt;br/&gt;
After;
&lt;pre&gt;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of notification@emailsan.com designates 49.212.10.123 as permitted sender) 
&lt;/pre&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;h2&gt;DKIM&lt;/h2&gt;
The easiest way to set DKIM should using dkim-filter. I just followed introduction and got no trouble.
&lt;a href=&#39;https://help.ubuntu.com/community/Postfix/DKIM&#39;&gt;PostfixDKIM&lt;/a&gt;

And I got this in raw email in Gmail;
&lt;pre&gt;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of notification@emailsan.com designates 49.212.10.123 as permitted sender) smtp.mail=notification@emailsan.com; dkim=pass (test mode) header.i=@emailsan.com
&lt;/pre&gt;
Note its seems that the majority using DKIM run it in test mode.&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
Hope this will save your time.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/2234179213774522469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/2234179213774522469'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2011/12/postfix-rails-on-ubuntu.html' title='Postfix + Rails on Ubuntu'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-8751168576806856636</id><published>2011-10-13T10:51:00.000+01:00</published><updated>2012-01-03T18:16:37.485+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>複数のファイルを同時にhtml2hamlする</title><content type='html'>複数のerbを同時にhamlに変換するbash scrpitです。&lt;a href=&quot;http://snot2000.wordpress.com/2009/11/28/html2haml-for-multiple-files/&quot;&gt;こちら&lt;/a&gt;を引用して作りました。


htmls2hamlsというファイルを以下の内容で設けます。
&lt;pre class=&#39;prettyprint&#39;&gt;

# Assume $1 is path to directory containing views in a rails project and $2 
: $1

if test -d $1 
then echo &#39;processing..&#39;
else echo Directory path must be specified for first argument; exit
fi

for i in $1/*.html.erb
do html2haml $i &gt; ${i%.erb}.haml
done

rm $1/*.html.erb

exit

&lt;/pre&gt;


以下のとおりに実行します。

&lt;pre class=&#39;prettyprint&#39;&gt;
cd RAILS_ROOT
htmls2hamls app/views/TARGETS
&lt;/pre&gt;


&lt;a href=&#39;https://gist.github.com/1283870&#39; &gt;gist &lt;/a&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/8751168576806856636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/8751168576806856636'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2011/10/html2haml.html' title='複数のファイルを同時にhtml2hamlする'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-1414843303742101874</id><published>2010-10-22T11:09:00.000+01:00</published><updated>2012-01-03T18:17:04.283+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Rails 3: Routing Examples</title><content type='html'>Rails3のルーティングがよくまとまってるところを見つけたのでノートします。&lt;br /&gt;
&lt;a href=http://markconnell.co.uk/posts/2010/02/rails-3-routing-examples&gt;Rails 3: Routing Examples&lt;/a&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/1414843303742101874'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/1414843303742101874'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2010/10/rails-3-routing-examples.html' title='Rails 3: Routing Examples'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-1604273215050674715</id><published>2010-10-11T14:49:00.009+01:00</published><updated>2011-10-26T11:33:09.327+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Note when installing Rails3 with RVM</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;h1&gt;Prerequisite&lt;/h1&gt;&lt;br /&gt;
&lt;br /&gt;
- ruby &amp;gt;= 1.8.7 but &lt;a href=&quot;http://edgeguides.rubyonrails.org/3_0_release_notes.html#rails-3-requires-at-least-ruby-1-8-7&quot;&gt;p248 and p249 crashes rails3&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
- gem &amp;gt;= 1.3.6&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;My environment&lt;/h1&gt;&lt;br /&gt;
&lt;br /&gt;
- Ubuntu&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION=&quot;Ubuntu 9.10&quot;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
- Rvm&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ rvm -v
rvm 0.1.44 &lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
To update your rvm to the latest version run the following command;&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ rvm update&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Since the version of ruby gems in my environment (Ubuntu karmic) is 1.3.5, I decided to use RVM and install ruby 1.8.7 (for a compatibility of other applications) and use rubygem 1.3.7.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;Installation&lt;/h1&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ rvm notes
Notes for Linux ( DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=karmic
DISTRIB_DESCRIPTION=&quot;Ubuntu 9.10&quot; )


*  NOTE: MRI stands for Matz&#39;s Ruby Interpreter (1.8.X, 1.9.X), ree stands for Ruby Enterprise Edition and rbx stands for Rubinius.


*  curl is required.

*  patch is required (for ree, some ruby head&#39;s).

*  If you wish to install rbx and/or any MRI head (eg. 1.9.2-head) then you must install and use rvm 1.8.7 first.

*  For JRuby (if you wish to use it) you will need:
$ aptitude install curl sun-java6-bin sun-java6-jre sun-java6-jdk
*  For MRI &amp;amp; ree (if you wish to use it) you will need (depending on what you are installing):
$ aptitude install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev vim libsqlite3-0 libsqlite3-dev sqlite3 libreadline5-dev libreadline6-dev libxml2-dev git-core subversion autoconf
*  For IronRuby (if you wish to use it) you will need:
$ aptitude install curl mono-2.0-devel&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is recommended to install the following packages beforehand because, without these, I encountered errors saying &#39;no such file to load&#39; by ruby.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ rvm pkg install iconv 
$ rvm pkg install readline 
$ rvm pkg install zlib
$ rvm pkg install autoconf
$ rvm pkg install openssl

$ export PATH=$HOME/.rvm/bin:$PATH

# To list all rubies you can install;
$ rvm list known

$ rvm install ruby-1.8.7-p299  -C --with-readline-dir=$HOME/.rvm/usr --with-iconv-dir=$HOME/.rvm/usr  --with-zlib-dir=$HOME/.rvm/usr --with-openssl-dir=$HOME/.rvm/usr

$ rvm use 1.8.7 &amp;amp;&amp;amp; ruby -v
info: Using ruby 1.8.7 p299
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]

$ gem -v
1.3.7&lt;/pre&gt;&lt;br /&gt;
&lt;br/&gt;
&lt;br/&gt;
If you got an error like bellow, one of packages above may not be correctly installed. &lt;br/&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
$ bundle exec rails c production
/home/suzukimilanpaak/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/completion.rb:9:in `require&#39;: no such file to load -- readline (LoadError)
 from /home/suzukimilanpaak/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/completion.rb:9:in `&lt;top (required)&gt;&#39;
 from /home/suzukimilanpaak/.rvm/gems/ruby-1.9.2-p290@global/gems/railties-3.0.9/lib/rails/commands/console.rb:3:in `require&#39;
 from /home/suzukimilanpaak/.rvm/gems/ruby-1.9.2-p290@global/gems/railties-3.0.9/lib/rails/commands/console.rb:3:in `&lt;top (required)&gt;&#39;
 from /home/suzukimilanpaak/.rvm/gems/ruby-1.9.2-p290@global/gems/railties-3.0.9/lib/rails/commands.rb:20:in `require&#39;
 from /home/suzukimilanpaak/.rvm/gems/ruby-1.9.2-p290@global/gems/railties-3.0.9/lib/rails/commands.rb:20:in `&lt;top (required)&gt;&#39;
&lt;/pre&gt;

If this&#39;s the case, execute following commands to reset ruby with newly compiled packages
&lt;pre class=&#39;prettyprint&#39;&gt;
rvm remove 1.9.2 
rvm cleanup all
rvm pkg install readline
rvm install ruby-1.9.2
&lt;/pre&gt;&lt;br/&gt;

&lt;br /&gt;
&lt;br /&gt;
Install Rails3 (Do not sudo when you using RVM, which will cause a permission denial or unreachable path when running console, a server and a rake task in your user privilege)&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ gem install rails -v 3.0.0&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Got this notice by rails -h&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ rails -h&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Could not find gem &#39;mysql2 (&amp;gt;= 0, runtime)&#39; in any of the gem sources.&lt;br /&gt;
Try running `bundle install`.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ bundle install
Fetching source index for http://rubygems.org/
Using rake (0.8.7) 
Using abstract (1.0.0) 
:
:
Using railties (3.0.0) 
Using rails (3.0.0) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Your bundle was installed to `/home/tatsuya/.rvm/gems/ruby-1.8.7-p299`&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;Create a new application&lt;/h1&gt;$ rails new apns&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$ rails server&lt;/pre&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/1604273215050674715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/1604273215050674715'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2010/10/note-when-installing-rails3-with-rvm.html' title='Note when installing Rails3 with RVM'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-6758697817819098194.post-5081135615809539569</id><published>2010-09-08T19:32:00.002+01:00</published><updated>2014-03-12T14:22:53.442+00:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ruby/ Ruby on Rails"/><title type='text'>Ruby on Railsを学び始めた人のためのリンク集</title><content type='html'>よく使う英語圏のRails関係のウェブサイトのノートです。たまに、付け足すかも&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- method名から用途を逆引きする&amp;nbsp;&lt;a href=&quot;http://apidock.com/&quot;&gt;API dock&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Ruby/ Rails/ RspcのAPI reference。メソッドの検索／仕様確認ができるだけでなく、他のユーザがあげているサンプルコードが勉強になる。URLがネームスペースと一緒になってるのも便利。&lt;br /&gt;
例 &lt;a href=&quot;http://apidock.com/rails/ActionView/Helpers/PrototypeHelper/link_to_remote&quot;&gt;ActionView::Helpers::PrototypeHelper&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
- Rubygems用途別比較サイト　&lt;a href=&quot;http://ruby-toolbox.com/&quot;&gt;The Ruby Tool Box&lt;/a&gt;&lt;br /&gt;
gemやpluginsがカテゴリーごとに載ってる。&lt;br /&gt;
&lt;br /&gt;
- gem serverの代わりにネット上で確認 &lt;a href=&quot;http://rdoc.info/&quot;&gt;RubyDoc.info&lt;/a&gt;&lt;br /&gt;
gem: --no-doc --no-riしてる人にお勧め&lt;br /&gt;
&lt;br /&gt;
- Best practiceを見たい &lt;a href=&quot;http://railscasts.com/&quot;&gt;Railscasts.com&lt;/a&gt;&lt;br /&gt;
例；Paypalなどの決済システムに接続するサンプル、メール送信をRSpecする方法など。&lt;br /&gt;
&lt;br /&gt;
- Ruby に限らず、技術的な質問はこちらへ &lt;a href=&quot;http://stackoverflow.com/&quot;&gt;Stack Overflow&lt;/a&gt;&lt;br /&gt;
良い回答が得られやすいのと、よくオーガナイズされている感じはQ＆A sitesでは一番だと思う。&lt;br /&gt;
&lt;br /&gt;
- Code Review をお願いする　&lt;a href=&quot;http://codereview.stackexchange.com/&quot;&gt;Code Review&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
- よくある実装のベストプラクティスがしりたい&lt;a href=&quot;http://rails-bestpractices.com/posts/702-don-t-rescue-exception-rescue-standarderror&quot;&gt;Rails Best Practice&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
- Railsをゲーム感覚で覚える &lt;a href=&quot;https://www.codeschool.com/courses/rails-best-practices&quot;&gt;Code School&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
- Rspecを例を見ながら学ぶ &lt;a href=&quot;https://relishapp.com/rspec&quot;&gt;Relish - RSpec&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
- Railsのベストプラクティスを学ぶ &lt;a href=&quot;http://ruby.railstutorial.org/&quot;&gt;Rails Tutorial&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
RSS readerに登録すると良いサイト&lt;br /&gt;
- &lt;a href=&quot;http://rubyquicktips.tumblr.com/&quot;&gt;Ruby quick tips&lt;/a&gt;&lt;br /&gt;
三分くらいで読めるような簡単なティップスをちょいちょい紹介しています。たまに当たりがあるので登録してて損はないです。&lt;br /&gt;
&lt;br /&gt;
- &lt;a href=&quot;http://www.splatbang.com/rubyquiz/&quot;&gt;Ruby Quiz&lt;/a&gt;&lt;br /&gt;
Rubyで一つのロジックを使って解けるくらいの問題を定期的に出題しています。僕にはたまにものすごく難しい&lt;br /&gt;
&lt;br /&gt;
ちょうどこんな記事を読んだので追記&lt;br /&gt;
- &lt;a href=&quot;http://weblog.rubyonrails.org/2010/8/28/rails-has-great-documentation?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed:+RidingRails+(Riding+Rails)&quot;&gt;Rails Has Great Documentation&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
英語圏に入るだけで得られる情報量がこんなに増える。日本語で二次情報を当るより、直接的にライブラリのドキュメント当たった方が間違いがなくて良い。その遠回りをするんだったらドキュメントを読める程度の英語を勉強した方が近道なんじゃないかなといつも思う。&lt;br /&gt;
&lt;br /&gt;
.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5081135615809539569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6758697817819098194/posts/default/5081135615809539569'/><link rel='alternate' type='text/html' href='http://engineerflies.blogspot.com/2010/09/rails.html' title='Ruby on Railsを学び始めた人のためのリンク集'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/01700091790800160715</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry></feed>