我有以下路线:
resources :businesses, only: [:show, :index, :new, :create] do
resources :pledge_drives
end
这将创建以下内容:
% rake routes | grep pledge
business_pledge_drives GET /businesses/:business_id/pledge_drives(.:format) pledge_drives#index
POST /businesses/:business_id/pledge_drives(.:format) pledge_drives#create
new_business_pledge_drife GET /businesses/:business_id/pledge_drives/new(.:format) pledge_drives#new
edit_business_pledge_drife GET /businesses/:business_id/pledge_drives/:id/edit(.:format) pledge_drives#edit
business_pledge_drife GET /businesses/:business_id/pledge_drives/:id(.:format) pledge_drives#show
PUT /businesses/:business_id/pledge_drives/:id(.:format) pledge_drives#update
DELETE /businesses/:business_id/pledge_drives/:id(.:format) pledge_drives#destroy
我不希望调用 URL 帮助程序方法business_pledge_drife_path
。如何纠正 Rails 的单数化drives
?实际的 URL 很好。
编辑: 这个答案是正确的。我将以下内容添加到 config/initializers/inflections.rb:
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural 'drive', 'drives'
inflect.singular 'drives', 'drive'
end
现在我的路线是:
business_pledge_drives GET /businesses/:business_id/pledge_drives(.:format) pledge_drives#index
POST /businesses/:business_id/pledge_drives(.:format) pledge_drives#create
new_business_pledge_drive GET /businesses/:business_id/pledge_drives/new(.:format) pledge_drives#new
edit_business_pledge_drive GET /businesses/:business_id/pledge_drives/:id/edit(.:format) pledge_drives#edit
business_pledge_drive GET /businesses/:business_id/pledge_drives/:id(.:format) pledge_drives#show
PUT /businesses/:business_id/pledge_drives/:id(.:format) pledge_drives#update
DELETE /businesses/:business_id/pledge_drives/:id(.:format) pledge_drives#destroy