I think that the complex Rails applications
such as maintained over years tend to have messy config/routes.
Today I'd like to introduce a simple way to keep them clean.

The way is really simple. Use with_options for each controller with prefix options.

rails>>
map.with_options(:controller => 'posts',
:name_prefix => 'posts_',
:path_prefix => 'posts') do |posts|

posts_rss_path => 'posts/rss'

posts.rss 'rss', :action => 'rss'
end
<<--

Still complex?
Okey, I have written the plugin for you.

With this plugin, you can draw the routes belonging to some controller like this.

rails>>
map.with_controller('posts') do |posts|
posts.rss # posts_rss_path => 'posts/rss'
end
<<--

As you can see, there's one more thing.
I have also installed MapperWithController class into RouteSet at this plugin for making named routes be completely DRY.

rails>>
class MapperWithController
def initialize(mapper)
@mapper = mapper
end

def method_missing(name, *args, &block)
path, *args = args
path ||= name.to_s
args.unshift path
@mapper.send name, *args, &block
end
end
<<--

map.namespace :posts does nearly same thing, but it couldn't be used for this purpose because of it is optimized to making namespaces for a routing.

posted by takiuchi takiuchi on Fri 14 Mar 2008 at 19:00 with 0 comments
Contents rssrss
Google +1 button causes trouble with Amazon ELB
How to build collada-dom on Linux
cmakeをhomeの下にインストールする手順のメモ
原子レベルのレンダリングに関するメモ
gluLookAtの等価表現
Where the Fl_Gl_Box is / Fl_Gl_Boxのありか
How to display the list of options for CMake
How to install collada-dom to MacOS X
積分方程式の分類について
Terminology of parallel computing needs recomposition
Tags
memocmakecolladaopengl3Damazonatomiccgcomputingdnselbfltkgoogleissuemacmathparallelreportthoughtsメモ
Comments rssrss
Spencer Spencer: You don't have to re-compile it, this version work... 04/08 07:15
staiano staiano: Any chance we can get a recompile for 10.9? 01/10 01:47
falsefalse falsefalse: @tiancongxin try using this one https://github.com... 02/14 08:04
tiancongxin tiancongxin: TerminalCopyOnSelect not work on OS X 'Lion' , cou... 07/21 17:21
staiano staiano: Roderick you rock for recompiling it. Thanks. 03/25 02:42
瀧内元気 瀧内元気: The merbi.st domain has been expired. So now it is... 01/03 17:25
Roderick Roderick: I've compiled the current version from github, thi... 08/24 15:57
swissarmychainsaw swissarmychainsaw: How do I get around this error message? Error Term... 08/20 20:43
Services from s21g
YOMU Web小説リーダー
小説投稿サイトの公式ページを開き、読みやすい表示、しおり、進捗保存、読み上げで読書を続けやすくするiPhoneアプリです。
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。
jotter.me
個人開発者のためのホスティング一体型ノートサービス
ハンドミラー
iPhone向けの手鏡アプリ
ツイプロ(twpro)
Twitterプロフィールの高速検索エンジン