Search code examples
ruby-on-railsrubyhttp-redirectroutesdepot

Route issue? Rails 'depot' issue with save_order redirecting


I am making a rails depot application. After a user selects items to buy and proceeds to checkout, I want to save their order. If the save fails, I want to redirect to the index. If the save succeeds, it should clear the session[:cart]. Then redirect the user to the catalogue page (the index action).

def save_order
  @cart = find_cart
  @order = Order.new(params[:order])
  if @order.save
    session[:cart] = nil
    redirect_to :action => “index”
  else
    redirect_to :action => “index”
  end
end

If the line redirect_to :action => “index” is included if the order saves, I simply get "We're sorry, but something went wrong" on chrome.

If I take it out, I get

Template is missing

Missing template store/save_order, application/save_order with {:locale=>[:en],
:formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "I:/13141-
CSC340A/Rails/Sites/depot3/app/views"

Any ideas?

Depot::Application.routes.draw do
  resources :orders

routes.rb

  get "store/index"
  post "store/add_to_cart"
  post "store/empty_cart"
  post "store/save_order"
  post "store/checkout"

  resources :products

Solution

  • I have a feeling the smart quotes around “index” could be a problem. Replace them with normal quotes.