04 Feb 2014, 00:36
Generic-user-small

SAPMUB (1 post)

Hi, I’m having a lot of issues trying to get the site to redirect to the main store page when an invalid cart is accessed. My carts_controller.rb is below:

def show
    begin
      @cart = Cart.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      logger.error "Attempt to access invalid cart #{params[:id]}"
      redirect_to store_url, :notice => 'Invalid cart'
    else
      respond_to do |format|
        format.html # show.html.erb
        format.xml { render :xml => @cart }
      end
    end
  end

When I attempt to access an invalid cart I still get the “ActiveRecord::RecordNotFound in CartsController#show” error. I’ve also tried replacing store_url with store_index_url.

Any ideas or suggestions? My routes are below:

Prefix Verb   URI Pattern                    Controller#Action
    line_items GET    /line_items(.:format)          line_items#index
               POST   /line_items(.:format)          line_items#create
 new_line_item GET    /line_items/new(.:format)      line_items#new
edit_line_item GET    /line_items/:id/edit(.:format) line_items#edit
     line_item GET    /line_items/:id(.:format)      line_items#show
               PATCH  /line_items/:id(.:format)      line_items#update
               PUT    /line_items/:id(.:format)      line_items#update
               DELETE /line_items/:id(.:format)      line_items#destroy
         carts GET    /carts(.:format)               carts#index
               POST   /carts(.:format)               carts#create
      new_cart GET    /carts/new(.:format)           carts#new
     edit_cart GET    /carts/:id/edit(.:format)      carts#edit
          cart GET    /carts/:id(.:format)           carts#show
               PATCH  /carts/:id(.:format)           carts#update
               PUT    /carts/:id(.:format)           carts#update
               DELETE /carts/:id(.:format)           carts#destroy
   store_index GET    /store/index(.:format)         store#index
      products GET    /products(.:format)            products#index
               POST   /products(.:format)            products#create
   new_product GET    /products/new(.:format)        products#new
  edit_product GET    /products/:id/edit(.:format)   products#edit
       product GET    /products/:id(.:format)        products#show
               PATCH  /products/:id(.:format)        products#update
               PUT    /products/:id(.:format)        products#update
               DELETE /products/:id(.:format)        products#destroy
         store GET    /                              store#index
  You must be logged in to comment