在我的Rails 3应用程序中,我希望能够路由到以下路径:
我有以下路线可以完成工作。
Moonshine::Application.routes.draw do
# Administration
match 'admin/automobiles/get_makes_for_year' => 'admin/automobiles#get_makes_for_year'
match 'admin/automobiles/get_models_for_make_and_year' => 'admin/automobiles#get_models_for_make_and_year'
namespace "admin" do
resources :automobiles
end
end
但是,以这种方式映射自定义路由不会感觉正确。有没有更好的方法来实现自定义控制器操作的路由?我在想有一种方法可以使用:controller, :action
通配符,或者像下面这样的东西。
Moonshine::Application.routes.draw do
# Administration
namespace "admin" do
resources :automobiles do
get :get_makes_for_year
get :get_models_for_make_and_year
end
end
end
答案 0 :(得分:4)
你可以这样做:
Moonshine::Application.routes.draw do
# Administration
namespace "admin" do
resources :automobiles do
get :get_makes_for_year, :on => :collection
get :get_models_for_make_and_year, :on => :collection
end
end
end