class ProductsController < ApplicationController
  before_filter :find_product, :only => [:show, :edit, :update]
  before_filter :admin_required, :except => [:show]

  def index
    @products = Product.all(:conditions => {:website_id => @w.id}, :order => :name)
  end
  
  def show
  end
  
  def new
    @product = Product.new
  end
  
  def edit
  end
  
  def create
    @product = Product.new(params[:product])
    @product.website_id = @w.id

    if @product.save
      flash[:notice] = "Successfully added new product."
      redirect_to :action => "new"
    else
      render :action => "new"
    end
  end
  
  def update
    if @product.update_attributes(params[:product])
      flash[:notice] = 'Product saved.'
      redirect_to product_path(@product)
    else
      render :action => 'edit'
    end
  end

  protected
  
  def find_product
    @product = Product.find(params[:id])
  end

end

class ProductsController < ApplicationController
  before_filter :find_product, :only => [:show, :edit, :update]
  before_filter :admin_or_manager_required, :except => [:show]

  def index
    @products = Product.all(:conditions => {:website_id => @w.id}, :order => :name)
  end
  
  def show
  end
  
  def new
    @product = Product.new
  end
  
  def edit
  end
  
  def create
    @product = Product.new(params[:product])
    @product.website_id = @w.id

    if @product.save
      flash[:notice] = "Successfully added new product."
      redirect_to :action => "new"
    else
      render :action => "new"
    end
  end
  
  def update
    if @product.update_attributes(params[:product])
      flash[:notice] = 'Product saved.'
      redirect_to product_path(@product)
    else
      render :action => 'edit'
    end
  end

  protected
  
  def find_product
    @product = Product.find_by_id_and_website_id(params[:id], @w.id)
    render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" if @product.nil?
  end

end

Allow managers to show, edit and update products; restrict products to current website or show 404 page if not found
Allow managers to show, edit and update products; restrict products to current website or show 404 page if not found
