This project is archived and is in readonly mode.
rails map.namespace的疑问
Reported by pure | July 11th, 2008 @ 04:07 PM | in 2.x
我定义了
map.resources :books # 前台
map.namespace :user do |user| #后台管理
user.resources :books
end
的路由,但请求user/books的时候有时候能正常转到user/books控制器,而有时却转到books控制器了,难道在user命名目录下的控制器必须不能同名?
根目录下
class BooksController < ApplicationController
user目录下的
class User::BooksController < ApplicationController
请求user/books时在BooksController 中输出控制器为user/books,但实现渲染的却是books目录下的视图而不是user/books目录下的视图
请求books/时时在BooksController 中输出控制器为books
请有知道的帮忙解释一下原因及解决方案!谢谢!
问题补充:
按理是没问题的,但就是请求一会儿正常一会又不正常,开始怀疑是不是session引起的,后面去掉大部分session问题依旧,就没再找session的原因了.下面是rotues.rb的全部代码:
ActionController::Routing::Routes.draw do |map|
map.root :controller=>'index'
map.resources :users
map.resources :news
map.resources :areas,:collection => { :json => :get,:switch => ost,:convert_code_name => ost }
map.resource :session
map.resources :salons,:member => { :vote => ost,:map => :get },:collection => { :search => :get },:has_many=>[ :comments,:fwus,:flacks,:jobs,:businesses ]
map.namespace :admin do |admin|
admin.root :controller => 'index'
admin.resources :areas
admin.resources :news
end
map.namespace :user do |user|
user.root :controller => 'index'
user.resources :salons,:has_many =>[ :fwus,:flacks,:jobs,:businesses ]
end
map.admin_top '/admin/top', :controller => 'admin/top', :action => 'index'
map.admin_menu_tree '/admin/menu_tree', :controller => 'admin/menu_tree', :action => 'index'
map.admin_main '/admin/main', :controller => 'admin/main', :action => 'index'
map.flacks '/flacks', :controller => 'flacks', :action => 'flacks'
map.jobs '/jobs', :controller => 'jobs', :action => 'jobs'
map.businesses '/businesses', :controller => 'businesses', :action => 'businesses'
map.user_profile '/user/profile', :controller => 'users', :action => 'edit'
map.signup '/signup', :controller => 'users', :action => 'new'
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.code_image '/code_image', :controller => 'code_image', :action => 'index'
map.user_show '/user/:name', :controller => 'users', :action => 'show'
end
问题补充:
Processing SalonsController#index (for 218.18.58.174 at 2008-06-24 22:02:05) [GET]
Session ID: BAh7CzoJdXNlcmkGOg5yZXR1cm5fdG8wIgpmbGFzaElDOidBY3Rpb25Db250
cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsAOglhcmVhbzoJ
QXJlYQk6EEBhdHRyaWJ1dGVzewkiCW5hbWUiGeW5v+S4nOecgSDmt7HlnLPl
uIIgIg91cGRhdGVkX2F0MCIJY29kZSIJNDQwMiIPY3JlYXRlZF9hdDA6FkBh
dHRyaWJ1dGVzX2NhY2hlewA6GEBjaGFuZ2VkX2F0dHJpYnV0ZXN7ByIJbmFt
ZTAiCWNvZGUwOhBAbmV3X3JlY29yZFQ6HGV4Y2VwdF9zZXRfY3VycmVudF9j
aXR5RjoMY3NyZl9pZCIlYTQ0NzZhZTgzZmY3NWE3Njk3MWYwMWY4YWM3MGU0
ZTI=--9566845969e09fab0176d713accdd750577dccb9
Parameters: {"action"=>"index", "controller"=>"user/salons"}
Rendering template within layouts/user
Rendering user/salons/index
------------------
Processing SalonsController#index (for 218.18.58.174 at 2008-06-24 22:02:05) [GET]
Session ID: BAh7CzoJdXNlcmkGOg5yZXR1cm5fdG8wIgpmbGFzaElDOidBY3Rpb25Db250
cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsAOglhcmVhbzoJ
QXJlYQk6EEBhdHRyaWJ1dGVzewkiCW5hbWUiGeW5v+S4nOecgSDmt7HlnLPl
uIIgIg91cGRhdGVkX2F0MCIJY29kZSIJNDQwMiIPY3JlYXRlZF9hdDA6FkBh
dHRyaWJ1dGVzX2NhY2hlewA6GEBjaGFuZ2VkX2F0dHJpYnV0ZXN7ByIJbmFt
ZTAiCWNvZGUwOhBAbmV3X3JlY29yZFQ6HGV4Y2VwdF9zZXRfY3VycmVudF9j
aXR5RjoMY3NyZl9pZCIlYTQ0NzZhZTgzZmY3NWE3Njk3MWYwMWY4YWM3MGU0
ZTI=--9566845969e09fab0176d713accdd750577dccb9
Parameters: {"action"=>"index", "controller"=>"user/salons"}
Rendering template within layouts/application
Rendering salons/index
问题补充:
class User::SalonsController < ApplicationController
layout 'user'
before_filter :login_required,:set_current_page,:non_salon_user
before_filter :find_salon,:except => [ :index,:new,:create ]
def index
@salons = current_user.salons.paginate(age => params[age],rder =>'id desc')
respond_to do |format|
format.html
format.xml { render :xml => @salons }
end
end
------------------------------
class SalonsController < ApplicationController
before_filter :login_required,nly => :vote
before_filter :set_current_page
before_filter :find_salon,:except => [ :index,:search ]
def index
@salons = Salon.paginate(age => params[age],:conditions =>["city like ?",current_area.code+"%"],rder =>'id desc')
respond_to do |format|
format.html
format.xml { render :xml => @salons }
end
end
有时如果没有登陆的话应该到登陆页面,结果还是去了salons/index
问题补充:
rails2.1 这个问题也不知道是什么原因造成的,非常不好调试,有时很难模拟测试.
问题补充:
http://www.imeifa.com.cn/salons
http://www.imeifa.com.cn/user/sa... //这个没有登陆应该到登陆页
Comments and changes to this ticket
-
Pratik October 12th, 2008 @ 08:26 PM
- State changed from new to invalid
Could you please get this translated to English ?
Thanks.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>