如何避免解决Rails中的路线?
|
我正在开发一个带有管理部分和公共部分的Rails应用程序。在公共部分,我只想解析索引并显示路线
resources :services, :only => [:index, :show]
但是,当我点击新操作的标准URL时,它将解析为ID为“'new \'”的show操作。那就是http://foo.com/services/new返回错误“找不到ID为新的服务”。无论如何,我可以告诉Rails不要解决/ services / new吗?
我已经尝试过
resources :services, :only => [:index, :show], :except => :new
和
resources :services, :except => :new, :only => [:index, :show]
没有成功。
ETA(根据要求):
我的整个路线文件(无注释):
MyApp::Application.routes.draw do
resources :services, :only => [:index, :show]
resources :packages,:only => [:index, :show]
get \"pages/home\"
get \"pages/about\"
get \"pages/help\"
root :to => \'packages#index\'
namespace \"admin\" do
get \"pages/home\"
get \"pages/about\"
get \"pages/help\"
resources :services
match \"/services/:id/add_to_package/:package_id\" => \"services#add_package\", :as => :add_package_to_service, :via => :post, :id => /\\d+/, :package_id => /\\d+/
match \"/services/:id/remove_from_package/:package_id\" => \"services#remove_package\", :as => :remove_package_from_service, :via => :post, :id => /\\d+/, :package_id => /\\d+/
resources :packages
match \"/packages/:id/add_service/:service_id\" => \"packages#add_service\", :as => :add_service_to_package, :via => :post, :id => /\\d+/, :service_id => /\\d+/
match \"/packages/:id/remove_service/:service_id\" => \"packages#remove_service\", :as => :remove_service_from_package, :via => :post, :id => /\\d+/, :service_id => /\\d+/
resources :users
root :to => \'pages#home\'
end
end
没有找到相关结果
已邀请:
1 个回复
哭木算
参数施加约束
这是假设您的
都是基于数字的。 我也遇到了类似的情况,即重定向与资源冲突,从而解决了该问题。