3 $
:.unshift(File
.dirname(__FILE__
) + "/../lib")
5 require "action_controller"
7 Post
= Struct
.new("Post", :title, :body)
9 class BlogController
< ActionController
::Base
10 before_filter
:initialize_session_storage
13 @posts = @session["posts"]
15 render_template
<<-"EOF"
19 <% @posts.each
do |post
| %>
20 <p
><b
><%= post
.title
%></b><br /><%= post
.body
%></p
>
24 <form action
="create">
25 Title
: <input type
="text" name
="post[title]"><br
>
26 Body
: <textarea name
="post[body]"></textarea
><br
>
27 <input type
="submit" value
="save">
35 @session["posts"].unshift(Post
.new(params
[:post][:title], params
[:post][:body]))
36 flash
["alert"] = "New post added!"
37 redirect_to
:action => "index"
41 def initialize_session_storage
42 @session["posts"] = [] if @session["posts"].nil?
46 ActionController
::Base.view_paths
= [ File
.dirname(__FILE__
) ]
47 # ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir
50 BlogController
.process_cgi(CGI
.new
) if $0 == __FILE__
52 CGI
.new
.out
{ "#{e.class}: #{e.message}" }