zend modules like in rails

2019-08-26 21:38发布

问题:

is there a way to do modules in rails 3 like zend framework modules ? In zend framework, you have a folder 'modules' like following structure:

/application/modules/admin
/application/modules/site
/application/modules/service 

and it's routed in this way:

http://myapp.local/admin
http://myapp.local/service
http://myapp.local/ -- to site module (default).

How can I achieve this in Rails 3? There's a better way to do this type things in rails ?

Thanks in advANCE

回答1:

How about controller namespaces?

                          # URL:
resources :projects       # /projects
resources :people         # /people

namespace "admin" do      # /admin
  resources :projects     # /admin/projects
  resources :people       # /admin/people
end

namespace "service" do    # /service
  resources :what         # /service/what
  resources :ever         # /service/ever
end

Controller paths:

app/controllers/projects_controller.rb
app/controllers/people_controller.rb
app/controllers/admin/projects_controller.rb
app/controllers/admin/people_controller.rb
app/controllers/service/what_controller.rb
app/controllers/service/ever_controller.rb

More information here:

http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing



回答2:

This is sounding a little like Models and Routes for Rails 3. I wouldn't say you need a specific model for Admin, that would be an extension of the User model.

The rails routing guide might put some of this in perspective.