rails namespace routes and controller

雨燕双飞 提交于 2019-12-25 05:46:08

问题


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

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

and under ...controller/manage/rooms_controller.rb and fuu_controller.rb and foo... example:

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

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

is the best way to do it via the controller e.g. render partial or changing the controller which the routes point to?

thanks!!!


回答1:


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.



来源:https://stackoverflow.com/questions/23457042/rails-namespace-routes-and-controller

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