Tôi đã có 2 bộ điều khiển:Rails tuyến đường: xác định gốc để namespace
app/
/controllers
posts_controllers.rb
/mobile
posts_controllers.rb
và routes.rb của tôi trông như thế này:
root :to => "posts#index"
resources :posts
namespace :mobile do
root :to => "posts#index"
resources :posts
end
nhưng khi tôi ghé thăm /mobile
, nó nào render index trang của bộ điều khiển đầu tiên, cũng đã thử điều này:
namespace :mobile do
root :to => "mobile/posts#index"
resources :posts
end
nhưng nó cho tôi lỗi: uninitialized constant Mobile::Mobile
Tôi muốn hiển thị trang chỉ mục của bộ điều khiển thứ hai, tôi có thể làm như thế nào?
Sửa
Bằng cách nhập/mobile tôi muốn làm cho các file nằm ở đây:
app/
views/
/mobile
/posts
index.html.erb
Nhưng nó xé file ở đây:
app/
views/
/posts
index.html.erb
Bạn đang làm tốt, chỉ cần kiểm tra xem lớp 'controllers/mobile/posts_controller.rb' giống như:' class Mobile :: PostsController
jan267