Route alias in Rails

后端 未结 3 1186
夕颜
夕颜 2020-12-08 13:15

I have a model stories in Rails 3.

I want to make an alias \"books\" for \"stories\" so I can have routes /books/192 instead of /stories/192

相关标签:
3条回答
  • 2020-12-08 13:47

    resources :stories, :path => :books

    If you want to rename the path AND helper methods, then you do:

    resources :stories, :path => :books, :as => :books

    See: Overriding the Named Helpers

    0 讨论(0)
  • 2020-12-08 13:49

    That's why they made the path option on match which is also available on resources:

    resources :stories, :path => "books"
    
    0 讨论(0)
  • 2020-12-08 13:53

    Try something like this:

    match 'books/:id' => 'books#show'
    match 'books' => 'books#index'
    
    0 讨论(0)
提交回复
热议问题