Rails:如何在具有范围的某些路径上设置参数,而在另一些路径上将其设置为nil?
|
我正在使用一些带有作用域的路由,有些则没有。见下文。
resources :cities
resources :categories
devise_for :clients
namespace :clients do
resources :account
resources :dashboard
resources :offers
end
scope \"/:current_city\" do
scope \"/:current_category\" do
match \'articles/last_articles\' => \'articles#index_last_articles\', :as => \"last_articles\"
resources :articles do
resources :comments
end
end
end
root :to => \"home#index\"
我正在使用这些参数:current_city和:current_category,它给了我一个类似的URL
当我访问文章时1ѭ。
**问题**
现在,我遇到了一个问题,如果我单击link_toities_path或root_path,则会将这两个参数添加为URL中的“ 2”。
我不希望这两个参数破坏URL的美感:o(
我发现的唯一方法是为每个链接传递:current_city => nil, :current_category => nil
,但这确实很繁重。我也尝试了同样的方法,但是在我的路由中,它适用于普通资源,但不适用于名称空间,root_path,devise_for路由,说实话,在route.rb中看起来很可怕。
**问题**
首先,我不明白为什么仅在有作用域的部分中问这些参数为什么会无处不在?
其次,有没有办法让它像我想要的那样工作,还是应该修改路线?
希望您理解我的问题,如果您有任何意见或想法,请不要犹豫!
谢谢
没有找到相关结果
已邀请:
0 个回复