class PostsController < ApplicationController

  def index
    list    
    render :action => 'list'
  end

  def list
    @posts = Post.find(:all,:order=>"lft")
  end

  def view
    @post = Post.find(params[:post])
    @parent = Post.find(@post.parent_id)
  end

  def new
    parent_id = params[:parent] || 1
    @parent = Post.find(parent_id)
    @post = Post.new
  end

  def reply 
    parent = Post.find(params[:parent])
    @post = Post.create(params[:post])
    parent.add_child(@post)
    if @post.save
      flash[:notice] = 'Wiadomość została opublikowana pomyślnie.'
    else    
      flash[:notice] = 'Wystąpił błąd!'
    end
    redirect_to :action => 'list'
  end
end