1

次のルートがあります。

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
4

1 に答える 1

1

ほとんどの場合、Rails は単語の正しい複数形 (例: モデル名) を認識しています。ただし、それ以外の場合は、屈折を使用してレールで正しい変換を定義できます。

于 2013-04-26T20:44:28.203 に答える