# Restful cart routing problems

**URL:** <https://www.ruby-forum.com/t/restful-cart-routing-problems/104279>\
**Category:** Rails\
**Created:** [May 16, 2007, 9:34am UTC](https://www.ruby-forum.com/t/restful-cart-routing-problems/104279 "2007-05-16T09:34:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [May 16, 2007, 9:34am UTC](https://www.ruby-forum.com/t/restful-cart-routing-problems/104279/1 "2007-05-16T09:34:44Z")

</div>

I want to have a cart with urls like this

it “should map { :controller =\> ‘cart’, :action =\> ‘index’ } to /cart”  
do  
route\_for(:controller =\> “cart”, :action =\> “index”).should ==  
“/cart”  
end

# it “should map { :controller =\> ‘cart’, :action =\> ‘show’, :id =\> 1 } to /cart/1” do route\_for(:controller =\> “cart”, :action =\> “show”, :id =\> 1).should

“/cart/1”  
end

# it “should map { :controller =\> ‘cart’, :action =\> ‘edit’,:id =\> 1} to /cart/1/edit” do route\_for(:controller =\> “cart”, :action =\> “edit”,:id =\> 1).should

“/cart/1/edit”  
end

it “should map { :controller =\> ‘cart’, :action =\> ‘update’,:id =\> 1 }  
to  
/cart/1” do  
route\_for(:controller =\> “cart”, :action =\> “update”,:id =\>  
1).should ==  
“/cart/1”  
end

it “should map { :controller =\> ‘cart’, :action =\> ‘destroy’,:id =\> 1}  
to  
/cart/1” do  
route\_for(:controller =\> “cart”, :action =\> “destroy”,:id =\>  
1).should  
== “/cart/1”  
end

That is, I want cart to act like a plural resource mapping for the  
singular  
cart\_items but I don’t know how to do this

map.resources :carts would give me urls like /carts/1

I tried to map it the long way  
map.with\_options(:controller =\> “cart”) do |m|  
m.cart\_url “/cart”,:action =\> “index”,:method =\> :get  
m.formatted\_cart\_url “/cart.:format”,:action =\> “index”,:method =\>  
:get  
m.cart\_item “/cart/:id”, :action =\> “show”, :method =\> :get  
m.connect “/cart/:id”, :action =\> “update”, :method =\> :put  
m.connect “/cart/:id”, :action =\> “destroy”, :method =\> :delete  
end

but this didn’t pass the above specification

What would be the best way to map this so I get the urls like above

Thanks,

dom

I
