removing log dir from .gitignore
[monkeycharger.git] / vendor / rails / actionpack / examples / blog_controller.cgi
blob506afad62fc4439926caa449529e242c199eca6f
1 #!/usr/local/bin/ruby
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
12 def index
13 @posts = @session["posts"]
15 render_template <<-"EOF"
16 <html><body>
17 <%= flash["alert"] %>
18 <h1>Posts</h1>
19 <% @posts.each do |post| %>
20 <p><b><%= post.title %></b><br /><%= post.body %></p>
21 <% end %>
23 <h1>Create post</h1>
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">
28 </form>
30 </body></html>
31 EOF
32 end
34 def create
35 @session["posts"].unshift(Post.new(params[:post][:title], params[:post][:body]))
36 flash["alert"] = "New post added!"
37 redirect_to :action => "index"
38 end
40 private
41 def initialize_session_storage
42 @session["posts"] = [] if @session["posts"].nil?
43 end
44 end
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
49 begin
50 BlogController.process_cgi(CGI.new) if $0 == __FILE__
51 rescue => e
52 CGI.new.out { "#{e.class}: #{e.message}" }
53 end