开发者

Rails: How to set params on some paths with scope and set them to nil on some others?

I'm using some routes with scopes, and some without. See below.

      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' => 'artic开发者_Go百科les#index_last_articles', :as => "last_articles"
              resources :articles do
                  resources :comments
              end
          end
      end
      root :to => "home#index"

I am using that params :current_city and :current_category and it gives me a URL like http://localhost:3000/warszawa/all/articles/last_articles when I'm accessing articles.

**PROBLEM**

I have now such a problem that if I click on a link_to cities_path or root_path, then it adds those two parameters to the URL as http://localhost:3000/?current_category=all&current_city=warszawa.

I don't want these two parameters destroying the beauty of my URL :o(

The only way I found was to pass :current_city => nil, :current_category => nil for each link, but that's really heavy. I tried also the same but in my routes, which is working for normal resources, but not for namespaces, root_path, devise_for routes, and to be honest, that looks horrible in the routes.rb.

**QUESTIONS**

  • First I do not understand why these params are passed everywhere if I ask them only in the section with scope?!

  • Secondly, is there a way to make it work like I want or I should modify my routes?

I wish you understand my problem and if you have any comment or idea, please do not hesitate!

Thx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜