Sha256: ac9ace3626e1e1e170da64e56f5a72b4cd59135077d587cecf3a343da3e7eaef
Contents?: true
Size: 1.99 KB
Versions: 1
Compression:
Stored size: 1.99 KB
Contents
# * George Moschovitis <gm@navel.gr> # (c) 2004-2005 Navel, all rights reserved. # $Id$ require 'nitro/controller' require 'nitro/builders/rss' require 'nitro/ui/pager' require 'lib/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', request, 3) @entries = BlogEntry.all("ORDER BY oid DESC #{@pager.sql_limit}") @pager.set(BlogEntry.count) end def new_entry entry = request.fill(BlogEntry.new) entry.author = session[:username] unless entry.valid? session[:errors] = entry.errors redirect_referer '#new_entry' end entry.save! end # example of action with parameter. The parameter # request['oid'] is referenced by the oid method # parameter. def myview(oid) entry = BlogEntry[oid] @out << entry.title end # example of generated view def list_entry__xml o.build_rss(@entries, :description => 'Blog entries', :link => context.host_url) end def new_comment comment = request.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.build_rss(@comments, :description => 'Blog comments', :link => context.host_url) end def login if password = request['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 Logger.info 'cache (after filter example)' end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nitro-0.11.0 | examples/blog/lib/blog/controller.rb |