覚えたTipsいろいろ

Railsでモジュールを組み込む際にbefore_filterを設定する

RailsOSSで独自の拡張を行いたいとき、できるだけ本体に触れないで拡張を行いたいときがあります。
そんなときはmoduleに設定してapplication_controller.rbでinclude "module"とかしてたのですが、before_filterなどをどうやって設定したらいいか分からず、
いつもapplication_controller.rbに追加してました。

それをmodule内で全て書けるようにできる方法を見つけたのでメモ。

module Hoge
  def self.included(controller)
    controller.class_eval do
       before_filter :hoge, :only => %w[new]
    end
  end
end
tcpflow

認証の仕組みを追いたかったのでtcpflowを入れてみた。
インストールはconfigure&make&make install。

使い方は sudo tcpflow -c port ****

ActiveRecord

ActiveRecordのconditionsは以下のような書き方ができることを最近知りました。(SKIPのおかげ)

class Hoge < ActiveRecord::Base
end

Hoge.find(:all,:conditions => [":from <= id < :to", {:from => 0, :to => 3}])