How to rename REST routes in URL?

前端 未结 2 1656
野趣味
野趣味 2020-12-25 12:32

Give that I have a model called Apple and it has a controller ApplesController, the routes are:

resources :apples

    apples  GET          


        
相关标签:
2条回答
  • 2020-12-25 12:48

    For those seeking only to rename the helper method part:

    resources :apples, as: "cars"
    

    I.e. this would replace apples_path with cars_path, but still using the same controller/action.

    0 讨论(0)
  • 2020-12-25 12:57

    What you will want to do is pass in the :path option

    resources :apples, :path => "cars"

    This replace all your route references with /apples to /cars

    See: http://guides.rubyonrails.org/routing.html, Section 4.7 Translating Paths

    0 讨论(0)
提交回复
热议问题