Railsで同じviewを使い回す時に知って得するメソッド4つ - おもしろWEBサービス開発日記

screenshot

リファレンスを見てたら偶然見つけたメソッドが使えそうだったのでまとめておきます。同じviewテンプレートを複数のアクションで使い回す時に使えます。 current_page? 指定したURLが、現在表示されていればtrueを返します。 例 link_to_if link_toの第一引数に条件文を書き、trueならリンクを有効に、falseならリンクを無行に(文字は表示されます)します。 例 link_to_unless link_to_ifのunless...

http://d.hatena.ne.jp/willnet/20080706/1215344347

current_page?(:controller => "main", :action => "index") # main#indexならtrue  へー。これは使えそう
current_page?, link_to_if などを上手く使おう,というお話
<%= link_to .... unless @hoge -%>とかしないでいいのか
[]「link_to_unless_current("ユーザ一覧",:controller=>"users",:action=>"in」
current_page?, link_to_if, link_to_unless, link_to_unless_current

http://b.hatena.ne.jp/entry/http://d.hatena.ne.jp/willnet/20080706/1215344347