ruby>>
map.resources :users
map.resource :session
<<--

routes.rbに出てくる、map.resource。綴り間違い??とひそかに思っていたらちゃんとありました。
map.resourceについてヘルプを見てみます。

Creates named routes for implementing verb-oriented controllers for
a singleton resource. A singleton resource is global to the current user visiting the application, such as a user‘s /account profile.

単数コントローラ名でパスを提供する場合に使えるようです。

  • a singular name is given to map.resource. The default controller name is taken from the singular name.
  • To specify a custom plural name, use the :plural option. There is no :singular option
  • No default index, new, or create routes are created for the singleton resource controller.
  • When nesting singleton resources, only the singular name is used as the path prefix (example: 'account/messages/1')
  • 単数形を使ったリソースを提供できます
  • :pluralオプションを使えば、複数を使うこともOK。:singularオプションはありません。
  • index, new, createのroutesは作られません
  • 入れ子で単数形resourceを使っている場合、prefixには単数形が使われます
    ex 'account/messages/1'

ヘルプにある生成されるというパスと私の環境のrake routesで表示されるパスが異なるようなので使用しているrailsで確認することが必要があるように思います。

posted by satoko satoko on Wed 28 Nov 2007 at 06:23 with 0 comments