0

我已经将我的rails应用程序分割为一个管理目录和一个公共目录。Rails命名空间控制器问题

admin目录位于Admin :: namespace(/ admin)中。

当我在Admin ::命名空间和普通根映射区域中创建了一个名为Forums的控制器时,路由似乎找到/ forums和/ admin/forums的Admin :: Forums控制器。

所以/管理/论坛=> “应用/控制器/管理/ forums_controller.rb” 所以/论坛=> “应用/控制器/管理/ forums_controller.rb”

不知道为什么发生这种情况,在两个控制器中都以某种方式继承了根控制器?当我尝试在非管理员论坛控制器内执行代码时,什么都不会受到干扰。

这里是我的路线:

map.resources :forums, :only => [:index,:show] do |forum| 
    forum.resources :topics, :shallow => true, :only => [:index,:show], :name_prefix => "" 
    end 

    map.namespace :admin, :name_prefix => "", :path_prefix => "/admin", :name_prefix => "admin_" do |admin| 

    admin.resources :forums, :name_prefix => 'admin_' do |forum| 
     forum.resources :topics, :name_prefix => 'admin_' do |topic| 
     topic.resources :posts, :name_prefix => 'admin_' 
     end 
    end 

    end 

任何想法?

+0

它是从你的其他问题有点重复:http://stackoverflow.com/questions/3146659/rails-2-namespace-and-shallow-routes-issue – shingara 2010-06-30 07:59:28

回答

1

您为主管理员命名空间调用指定了两次name_prefix(这实际上是随机选择一个选项)。您也不需要子资源中的name_prefix选项。这是我的应用程序 - 命名空间中的一些子资源(问题和用户)也是主要资源,不存在混淆。

map.namespace :admin do |admin| 
    admin.resources :home, :only => [:index] 
    admin.resources :questions, :collection => {:edit_by_text => :get, :update_by_text => :post, :import_progress => :post} 
    admin.resources :users 
    admin.resources :subjects, :member => {:make_quizzes => :post} 
    end