Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

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

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!!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...