[Rails] Relative Path プラグインバージョンアップ
最近少し放置していた、Relative Path プラグインに対し少し手を入れました。
今のところ、trunk にだけ反映しています。
主な改修点は次のとおりです。
- Controller での url_for の動作の不具合を修正
- ur_for の :absolute_path オプションを廃止
- :absolute_path の代替として、with_relative_path_disabled ブロックを導入
- テストを一部の処理について作成
- WEBrick , Mongrel の動作の変更を include 時に
- 特定の Controller では、Relative Path プラグインを使わないといった指定を可能に
- http://opensvn.csie.org/relative_path/tags/relative_path ディレクトリを stable バージョンに
- ./plugin/install http://opensvn.csie.org/relative_path/tags/relative_path で簡単にインストール可能に
with_relative_path_disabled と特定の Controller で Relative Path プラグインを使わないことについて、簡単に解説します。
次の例がわかりやすいでしょうか?
# app/controllers/application.rb class ApplicationController < ActionController::Base include RelativePath end # app/controllers/enabled_controller.rb class EnabledControlelr < ApplicationController end # app/controllers/disabled_controller.rb class DisabledControlelr < ApplicationController disable_relative_path end # app/views/enabled/index.rhtml <%= link_to 'before', :action => 'index' %> <% with_relative_path_disabled do %> <%= link_to 'relative_path_disabled', :action => 'index',:only_path => false %> <% with_relative_path_enabled do %> <%= link_to 'relative_path_enabled', :action => 'index' %> <% end %> <%= link_to 'relative_path_disabled2', :action => 'index' %> <% end %> <%= link_to 'after', :action => 'index' %> # app/views/disabled/index.rhtml <%= link_to 'before', :action => 'index' %> <% with_relative_path_enabled do %> <%= link_to 'relative_path_enabled', :action => 'index',:only_path => false %> <% with_relative_path_disabled do %> <%= link_to 'relative_path_disabled', :action => 'index' %> <% end %> <%= link_to 'relative_path_enabled2', :action => 'index' %> <% end %> <%= link_to 'after', :action => 'index' %>
上記の例では、 app/views/enabled/index.rhtml では上から順に
というように表示されます。
app/views/disabled/index.rhtml では、上から順に
のように表示されます。
disable_relative_path が実行されている Controller では、デフォルトの動作が Relative Path プラグインを include していない場合と同じになります。
また、 enable_relative_path というメソッドも対称性の観点から用意していますが、あまり使われることはないでしょう。
あと、Hidden Field Session という新しい Rails プラグインも作成してみました。
- http://wiki.rubyonrails.org/rails/pages/Hidden+Field+Session
- http://opensvn.csie.org/hidden_field_session/trunk/hidden_field_session/
これは、ActiveHeart の中にあった、trans_sid という Cookie を使わないセッション管理の部分だけを切り出して、現在のバージョンの Rails で正しく動作するようにしたものです。
かなり大幅に書き直しています。
Relative Path プラグインと同じように、特定の Controller でだけ有効・無効にするということを可能にしたり、Rails 1.2 の改修に対応して、session_options 関係を正しく動作するように変更しています。