zend modules like in rails

人盡茶涼 提交于 2019-12-11 22:49:46

问题


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.



来源:https://stackoverflow.com/questions/5264583/zend-modules-like-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!