我無法爲我的控制器創建一個模塊,並讓我的路線指向控制器內的那個模塊。Rails路由和控制器模塊 - 名稱間隔?
收到此錯誤:
Routing Error
uninitialized constant Api::Fb
所以,這是我的路線是如何設置:
namespace :api do
namespace :fb do
post :login
resources :my_lists do
resources :my_wishes
end
end
end
在我fb_controller我想包括的模塊,這將使我的路徑是這樣的:
/api/fb/my_lists
這是我的一些fb_controller:
class Api::FbController < ApplicationController
skip_before_filter :authenticate_user!, :only => [:login]
include MyLists # <-- This is where i want to include the /my_lists
# namespace(currently not working, and gives me error
# mentioned above)
def login
#loads of logic
end
end
MyLists.rb文件(其中我定義了一個模塊)與fb_controller.rb位於同一目錄中。
如何獲取命名空間以指向fb_controller中的模塊,如/ api/fb/my_lists?
謝謝!如果我喜歡你的建議,將路線指向我的模塊包含在FbController中?我想要的基本上只是一個主要模塊,並以匹配路線的方式嵌套「子模塊」。 fb控制器允許您編輯/創建包含許多願望的列表。所以我希望list_controller是fb_controller的子模塊,wish_controller是列表控制器的子模塊。那有意義嗎? – 2013-03-20 19:32:53
我認爲你有控制器和模塊混淆。我會以我如何處理你想要做的事情的例子來更新我的答案。 – 2013-03-20 19:44:38
那太棒了,謝謝Leo! – 2013-03-20 19:52:09