开发者

Rails Routes: Nested Scopes/Namespaces

Right now I have an admin.domain.com subdomain for which there is a module scope:

  constraints(AdminDomain) do
    scope :module => "admin" do
      resources :visitors
    end
  end

This makes all requests on the admin subdomain hit controllers in app/controllers/admin/.

What I'd like to do now is something like:

  constraints(AdminDomain) do
    scope :module => "admin" do
      resources :visitors
      scope "history", :as => "history" do
        resources :visi开发者_C百科tors
      end
    end
  end

Where the end goal is to make admin.domain.com/history/visitors hit controller: app/controllers/admin/history/visitors_controller.rb.

This path however still looks for app/controllers/admin/visitors_controller.rb.

Any ideas?


namespace is what I was looking for:

  constraints(AdminDomain) do
    scope :module => "admin" do
      resources :visitors
      namespace :history do
        resources :visitors
      end
    end
  end

And I had to define Admin::History::VisitorsController in app/controllers/admin/history/visitors_controller.rb


easy way to define specific controller is just like:

:controller => admin/history/visitors
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜