-1

I have a Rails 4 app and currently implementing a shopping cart. i dont want to reveal the user id, cart id but only the cart items id in the url. so basically, i want my routes to be something like ;-

/user/cart/plans => show all plans
/user/cart/cart_items/new => add to cart
/user/cart => show current cart with cart items
/user/cart/cart_item DESTROY - delete item from cart

so in my routes.rb

resource :user, only: [:edit] do
  collection do
    patch 'update_password'
    get 'show_payment_history'
  end
  resource :cart
  resources :cart_items ,  only: [:new, :destroy]   
  ...
  ...

and the path, that go generated using above routes is ...

   update_password_user PATCH    /user/update_password(.:format)                                                                             users#update_password
                             show_payment_history_user GET      /user/show_payment_history(.:format)                                                                        users#show_payment_history
                                             user_cart POST     /user/cart(.:format)                                                                                        carts#create
                                         new_user_cart GET      /user/cart/new(.:format)                                                                                    carts#new
                                        edit_user_cart GET      /user/cart/edit(.:format)                                                                                   carts#edit
                                                       GET      /user/cart(.:format)                                                                                        carts#show
                                                       PATCH    /user/cart(.:format)                                                                                        carts#update
                                                       PUT      /user/cart(.:format)                                                                                        carts#update
                                                       DELETE   /user/cart(.:format)                                                                                        carts#destroy
                                    new_user_cart_item GET      /user/cart_items/new(.:format)                                                                              cart_items#new
                                        user_cart_item DELETE   /user/cart_items/:id(.:format)                                                                              cart_items#destroy

But i am still not able to make it work,For example, user_cart_path do not work in redirection, dont know...whats the issue.

Any help will be appreciated or any good approach for my suggested solution!

Thanks in advance

Milind
  • 4,136
  • 1
  • 21
  • 51

1 Answers1

0

The issue was related to pluralizing the controller name.Once i renamed the controller from cart to carts...everything got fixed.

Hope it helps others

Milind
  • 4,136
  • 1
  • 21
  • 51