我有不同的命名空间控制器,它们共享相同的布局:
# /app/controllers/admin/dashboard.rb
class Admins::DashboardController < ApplicationController
...
end
# /app/controllers/clients/dashboard.rb
class Clients::DashboardController < ApplicationController
...
end
这是我的目录结构:
App
|_ Controllers
| |_ Admins
| | |_ dashboard_controller.rb
| |_ Clients
| |_ dashboard_controller.rb
|
|_ Views
|_ Admins
| |_ Dashboard
| |_ index.html.erb
|
| |_ show.html.erb
|_ Clients
| |_ Dashboard
| |_ index.html.erb
| |_ show.html.erb
|_ layouts
|_ admin.html.erb
|_ _sidebar.html.erb
我想确定布局是否显示Admins
或Clients
显示正确的侧边栏,例如:
<% if admins? %>
...
<% elsif clients? %>
...
<% end %>
这甚至是解决此问题的最佳方法还是有更好的解决方案?