0

複数のリソース(:countries, :states, :schoolsなど)がありますが、1つの「ダッシュボード」コントローラーですべてのアクションを処理したいと思います。

私は次のことができるようになりたいです:

countries_pathshow_countriesのアクションに私をDashboardController導き、によってアクセス可能になります'/dashboard/countries

州、学校なども同様です。

私はRailsルーティングについて読み、さまざまなオプションをいじっています。私のroutes.rbファイルには次のようなものがありました。

scope "toolbox" do
  resources :countries, :controller => "toolbox", :only => :index do
    get 'show_countries', :on => :collection
  end

  ...
end

実行rake routesすると、上記のコードに対して次のようになります。

show_countries_countries GET    /toolbox/countries/show_countries(.:format)  {:action=>"show_countries", :controller=>"toolbox"}
countries GET    /toolbox/countries(.:format)  {:action=>"index", :controller=>"toolbox"}

私はこれを試しました:

scope "toolbox" do
  resources :countries, :controller => "toolbox", :only => :index, :action => "show_countries"
end

このルートを取得するためだけに:

countries GET    /toolbox/countries(.:format)  {:action=>"index", :controller=>"toolbox"}

私が本当に欲しいのはこれです:

countries GET    /toolbox/countries(.:format)  {:action=>"show_countries", :controller=>"toolbox"}

何か案は?

4

1 に答える 1

1

「リソース」ボックスの外で考える必要があります。

scope "toolbox", :controller => :toolbox do
  get 'countries' => :show_countries
  get 'states' => :show_states
  get 'schools' => :show_shools
end

次のようなルートを出力する必要があります。

countries GET /toolbox/countries(.:format) toolbox#show_countries
于 2012-12-28T21:55:07.443 に答える