Archive for category Ruby on Rails

returning は死んだ。 Object#tap を使おう

標記のとおり、死ぬみたいです。

crankharder

I’m curious to know what the rational is behind this?

rohit

You can now use tap.

正論過ぎて返す言葉もありませんね。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
require "rubygems"
require "active_support"
 
a1 = returning [] do |ary|
  ary << 'hoge'
  ary << 'fuga'
end
 
a2 = [].tap do |ary|
  ary << 'hoge'
  ary << 'fuga'
end
 
require "spec"
a1.should == a2
#=> true

確かに、タイピング量的にも、tapの方が少なくなりますね。でも、1.8.6みたいにtapのバックポートが無い場合とか、あとreturningを使いまくってる場合は…。

そもそもtapもreturningも4行ぐらいで実装できるので、以下のような config/initializers/returning_strikes_back.rb を作成すれば互換性を確保できるんじゃあないでしょうか。あまり薦めませんが。。

1
2
3
4
5
6
7
8
9
10
module ReturningStrikesBack
  def returning(value)
    yield(value)
    value
  end
end
 
class Object
  include ReturningStrikesBack
end

Nginx+Passengerで、 / と /hoge に別々のRails appをデプロイする

単純に /hoge と /fuga に別々のアプリケーションをdeployするのなら、話は単純で、以下のチュートリアルのとおりなんですが。

問題は passenger_base_uri に「/」を指定できないこと。

方針としては、「/」のアプリケーションと「/hoge」のアプリケーションは別々のポートで配備して、かつ「/」をデプロイした側から、リバースプロキシで「/hoge」に飛ばしてあげる、という感じです。Pound辺りと組み合わせてもいいんですが、Nginxだけで完結できます。

Read the rest of this entry »

Ubuntuに、passenger-install-nginx-moduleした

Ubuntuは、aptitudeでNginxが入るんだけど、Passenger対応しているわけではない。ビルド時に指定しないとPassengerのモジュールが組み込まれないから。

以下は、passenger対応させた上でinitスクリプトの登録までする手順。

Read the rest of this entry »