Specific routing problem

I am implementing a system for users to easily create a small shop for
themselves. And I’ve run into a route problem.

NOTE: I’ve removed a lot from my route.rb file, since I want focus on
this particular problem. :slight_smile:

I currently have a route.rb like this:

ActionController::Routing::Routes.draw do |map|
map.resources :shops do |shops|
shops.resource :cart, :member => { :clear => :put } do |cart|
cart.resources :items
end
end
end

This makes possible URLs like these:

http://myshop.com/shop/13
http://myshop.com/shop/13/cart
http://myshop.com/shop/13/cart/items
http://myshop.com/shop/13/cart/clear
etc.

The thing is, I really want URLs where the first keyword “shop” is
removed, ie:

http://myshop.com/13
http://myshop.com/13/cart
http://myshop.com/13/cart/items
http://myshop.com/13/cart/clear

Or - better still - every shop has a nickname, so it should be

http://myshop.com/davids-modeltrains
http://myshop.com/davids-modeltrains/cart
http://myshop.com/diamonds-for-all/cart/clear
etc.

Using a nickname instead of an ID is not the problem for me. My problem
is, I cannot find out how to make my route.rb, to fit this.

I hope somebody can help.

Thanks

  • Carsten

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs