【问题标题】:How can connect routes in rails 3 using folders?如何使用文件夹连接 Rails 3 中的路线?
【发布时间】:2016-01-11 21:41:02
【问题描述】:

我收到一个错误没有路线匹配 [GET],因为尝试为每个控制器创建文件夹

这里是应用结构:

|controller,helper,view|
 |user_management| ------> FOLDER
   |user|          ------> SUBFOLDER  
   |login|         ------> SUBFOLDER    
   |chat|          ------> SUBFOLDER  
 |sale_management| ------> FOLDER  
   |sale|          ------> SUBFOLDER  
   |product|       ------> SUBFOLDER  

这里的控制器:

 # UserManagement Controllers
 class UserManagement::UserController < ApplicationController
 class UserManagement::LoginController < ApplicationController
 class UserManagement::ChatController < ApplicationController

 # SaleManagement Controllers
 class SaleManagement::SaleController < ApplicationController
 class SaleManagement::ProductController < ApplicationController

这里的助手:

 module UserManagement::UserHelper
 module UserManagement::LoginHelper
 module UserManagement::ChatHelper
 module SaleManagement::SaleHelper
 module SaleManagement::ProductHelper

来自 rails 2.3 和 ruby​​ 1.8 的 Router.rb

map.root :controller => "user_management/user", :action=>"index"
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

我正在使用 rails 3 和 ruby​​ 1.9 中的 Routes.rb 但得到 ROUTES ERROR

root :to => 'user_management/user#index'
match ':controller(/:action(/:id))(.:format)'

有人可以帮助我吗?

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 ruby-1.9.3


    【解决方案1】:

    这里是例子

    scope module: 'user_management' do
       scope module: 'user' do
          resources :users
       end
    end
    

    然后就可以访问users 像localhost:3000/users

    更多详情请查看Rails Routing

    【讨论】:

    • 不工作我正在尝试使用 localhots/user_management/user/login 并且我得到 No route matches [GET] "/user_management/user/index"
    • 感谢 +1...花了一些时间让我终于了解 Rails 4。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多