# * George Moschovitis # (c) 2004-2005 Navel, all rights reserved. # $Id$ require 'nitro/controller' require 'nitro/builders/rss' require 'nitro/ui/pager' require 'blog/model' # The controller of the Blog part. class BlogController < N::Controller before_filter :get_errors # after_filter :cache scaffold BlogEntry, :name => 'entry', :index => true scaffold Comment def list_entry @pager = UI::Pager.new('entries', context, 3) @entries = BlogEntry.all("ORDER BY oid DESC #{@pager.sql_limit}") @pager.set(BlogEntry.count) end def new_entry entry = context.fill(BlogEntry.new) entry.author = session[:username] unless entry.valid? session[:errors] = entry.errors redirect_referer '#new_entry' end entry.save! end # example of generated view def list_entry__xml @out << RssBuilder.render(@entries) end def new_comment comment = context.fill(Comment.new) unless comment.valid? session[:errors] = comment.errors redirect_referer '#new_comment' end comment.save! end # example of generated view def list_comment__xml @out << RssBuilder.render(@comments) end def login if password = context['password'] if password == Blog.password session[:owner] = true session[:username] = Blog.username redirect '/' else @error = 'Invalid password' end end end def logout session.delete(:owner) session.delete(:username) end private # A helper prefilter, autocleans session errors. # Used as an example. def get_errors # gmosx: should better implement top-level filters! if errors = session.delete(:errors) @errors = errors end end # Just an example. def cache # Call the automatically configured logger. Logger.info "cache (after filter example)" end end