Changeset 1089

Show
Ignore:
Timestamp:
09/30/08 23:00:37 (18 months ago)
Author:
vasi
Message:

error handling

Location:
rails_book/depot/app
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • rails_book/depot/app/controllers/store_controller.rb

    r1087 r1089  
    55   
    66  def add_to_cart 
    7     @cart = find_cart 
    8     product = Product.find(params[:id]) 
    9     @cart.add_product(product) 
     7    begin 
     8      product = Product.find(params[:id]) 
     9    rescue ActiveRecord::RecordNotFound 
     10      logger.error("Attempt to access invalid product #{params[:id]}") 
     11      flash[:notice] = "Invalid product" 
     12      redirect_to :action => :index 
     13        else 
     14          @cart = find_cart 
     15          @cart.add_product(product) 
     16        end 
    1017  end 
    1118   
  • rails_book/depot/app/views/layouts/store.html.erb

    r1083 r1089  
    1717    </div> 
    1818    <div id="main"> 
     19      <% if flash[:notice] -%> 
     20        <div id="notice"><%= flash[:notice] %></div> 
     21      <% end -%> 
    1922      <%= yield :layout %> 
    2023    </div>