簡體   English   中英

Rails3-路由自定義控制器操作

[英]Rails3 - Routing Custom Controller Actions

在我的Rails 3應用程序中,我希望能夠路由到以下路徑:

  • /管理/汽車/ get_makes_for_year
  • /管理/汽車/ get_models_for_make_and_year

我有以下路線可以完成工作。

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

你可以做:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM