class ItemsController < ApplicationController
  def list
    @item_pages, @items = paginate :items, :per_page => 10
  end

  def show
    @item = Item.find(params[:id])
  end

  def new
  end

  def create
    @item = Item.new(params[:item])

    if @item.save
      flash[:error] = 'Wystpi problem.'
      redirect_to :action => 'new'
      return  
    end

    unless params[:photo]['photo'].content_type =~ /^image/
      flash[:error] = 'Wybierz plik do wysania.'
      render :action => 'new'
      return  
    end

    @photo = Photo.new(params[:photo])
    @photo.item_id = @item.id

    if @photo.save
      flash[:notice] = 'Element zosta uwtorzony.'
      redirect_to :action => 'list'
    else    
      flash[:error] = 'Wystpi problem.'
      render :action => 'new'
    end
  end
end