Rails の routes.rb がわかりにくい
Rails の routes.rb と格闘中なんだけど、なんで Rails の routing はこんなにわかりにくいのだろうか。
## named route は省略 map.with_options(:controller=>'books') do |x| x.connect '/books', :action=>'index', :conditions=>{:method=>:get} x.connect '/books', :action=>'create', :conditions=>{:method=>:post} x.connect '/books/new', :action=>'new', :conditions=>{:method=>:get} x.connect '/books/:title', :action=>'show', :conditions=>{:method=>:get} x.connect '/books/:title', :action=>'update', :conditions=>{:method=>:put} x.connect '/books/:title', :action=>'delete', :conditions=>{:method=>:delete} x.connect '/books/:title/edit', :action=>'edit', :conditions=>{:method=>:get} end
なんか、もう、こう、ね、もっとわかりやすく書きたいよね。
こうじゃだめなんだろうか。
map.with_options(:controller=>BooksController) do |x| x.connect '/books', :GET=>'index', :POST=>'create' x.connect '/books/new', :GET=>'new' x.connect '/books/:title', :GET=>'show', :PUT=>'update', :DELETE=>'delete' x.connect '/books/:title/edit', :GET=>'edit' end
こっちのほうが簡潔でわかりやすいや。「リクエストパスとリクエストメソッドからアクションが決定される」という仕組みも一目瞭然だし。Rails の書き方だとそのへんが見えにくい。