From db045dbbf60b53dbe013ef25554fd013baf88134 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 24 Nov 2004 01:04:44 +0000 Subject: Initial git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/examples/blog_controller.cgi | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 actionpack/examples/blog_controller.cgi (limited to 'actionpack/examples/blog_controller.cgi') diff --git a/actionpack/examples/blog_controller.cgi b/actionpack/examples/blog_controller.cgi new file mode 100755 index 0000000000..e64fe85f0c --- /dev/null +++ b/actionpack/examples/blog_controller.cgi @@ -0,0 +1,53 @@ +#!/usr/local/bin/ruby + +$:.unshift(File.dirname(__FILE__) + "/../lib") + +require "action_controller" + +Post = Struct.new("Post", :title, :body) + +class BlogController < ActionController::Base + before_filter :initialize_session_storage + + def index + @posts = @session["posts"] + + render_template <<-"EOF" + + <%= @flash["alert"] %> +

Posts

+ <% @posts.each do |post| %> +

<%= post.title %>
<%= post.body %>

+ <% end %> + +

Create post

+
+ Title:
+ Body:
+ +
+ + + EOF + end + + def create + @session["posts"].unshift(Post.new(@params["post"]["title"], @params["post"]["body"])) + flash["alert"] = "New post added!" + redirect_to :action => "index" + end + + private + def initialize_session_storage + @session["posts"] = [] if @session["posts"].nil? + end +end + +ActionController::Base.template_root = File.dirname(__FILE__) +# ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir + +begin + BlogController.process_cgi(CGI.new) if $0 == __FILE__ +rescue => e + CGI.new.out { "#{e.class}: #{e.message}" } +end \ No newline at end of file -- cgit v1.2.3