开发者

Rails Namespace Controller Issue

开发者 https://www.devze.com 2023-01-05 00:52 出处:网络
I\'ve split my rails app into a admin directory and a public directory. The admin directory is within an Admin:: namespace (/admin).

I've split my rails app into a admin directory and a public directory.

The admin directory is within an Admin:: namespace (/admin).

When I created a controller called Forums in both the Admin:: namespace and the normal root map area, the routing seems t开发者_Python百科o find the Admin::Forums controller for /forums and /admin/forums.

So /admin/forums => "app/controllers/admin/forums_controller.rb" So /forums => "app/controllers/admin/forums_controller.rb"

Not sure why this is happening, are the root controllers somehow inherited amoung both controllers? When I try to execute code within the non-admin forums controller, nothing gets exercuted.

Here is my route:

  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

Any ideas?


You specify the name_prefix twice for the main admin namespace call (which is going to essentially choose one option at random). Also you don't need the name_prefix option in the sub resources. Here's mine from my app - some of the sub resources in the namespace (questions and users) are also main resources and there's no confusion.

  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
0

精彩评论

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