0

在 routes.rb 中:

scope "(:locale)", locale: /en|de/ do
    get 'service' => 'service#index'
    get 'service/:id' => 'service#show'
end

然后在视图中我使用 helperservice_path(params[:locale], id)并获取此链接/en/service.1。但我需要这样的链接/en/service/1

通过以下方式检查路由rake routes

service GET    (/:locale)/service(.:format)   service#index (locale=>/en|ru/}
        GET    (/:locale)/service/:id(.:format)  service#show {:locale=>/en|ru/}

如何获得正常的链接,例如/en/service/1,我做错了什么?

4

1 回答 1

1

您应该将控制器重命名为复数形式Services

路线变化:

get 'service' => 'service#index'get 'services' => 'services#index', :as => :services

得到'service/:id' => 'service#show'得到'services/:id' => 'services#show', :as => :service

或者你可以写简单的:

resources :services, :only => [:show, :index]
于 2013-08-26T08:48:27.537 回答