简体   繁体   English

Rails名称空间路由和控制器

[英]rails namespace routes and controller

i just can not figure out the best way to handle the routes / controller with the following namespace. 我只是不知道使用以下名称空间来处理路由/控制器的最佳方法。 i´d just like to have the following setup: 我只想进行以下设置:

.../manage/rooms/  ( <%= @ rooms.number_of_rooms%>, <%= @ rooms.title %> )
.../manage/fuu/     ( <%= @ fuu.id %>...) 
..manage/foo/       ...

i know this is done by routes.rb 我知道这是由routes.rb完成的

namespace :manage do
resources :rooms, :fuu, :foo
end

and under ... controller/manage/rooms_controller.rb and fuu_controller.rb and foo... example: 并在... controller/manage/rooms_controller.rbfuu_controller.rbfoo...

class Manage::RoomsController < ApplicationController

 index
 @rooms = Rooms.all
 end
 def create
 @room = Room.new(room_params)
  if @room.save
   redirect_to [:manage, @room]
  else
   render 'new'
 end
 ...
end

and a controller under controller/manage_controller.rb 和一个在controller/manage_controller.rb下的controller/manage_controller.rb

class ManageController < ApplicationController
end

so here is my question i do like to use all of my forms and variables @rooms.title... who are under .../manage/rooms/ .../manage/fuu/ .... under the .../manage/index.html.erb 所以这里是我的问题,我想用我所有的形式和变量@rooms.title...谁是下.../manage/rooms/ .../manage/fuu/ ......./manage/index.html.erb

is the best way to do it via the controller eg render partial or changing the controller which the routes point to? 通过控制器做到这一点的最佳方法是例如局部渲染或更改路线指向的控制器?

thanks!!! 谢谢!!!

I would use partials in this situation. 在这种情况下,我会使用局部函数。 If they are all shared in that namespace, it makes sense for the location to be the manage views directory. 如果它们都在该命名空间中共享,则将该位置作为管理视图目录是有意义的。 If they weren't namespaced but still being shared, I'd create a 'shared' directory in views. 如果它们没有命名空间但仍在共享中,那么我将在视图中创建一个“共享”目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM