Sha256: 963740439ebb306a553b4f13766b150c4ef95d34f1282ad1fac673c3309e3c90

Contents?: true

Size: 1.33 KB

Versions: 22

Compression:

Stored size: 1.33 KB

Contents

#!/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"
      <html><body>
      <%= flash["alert"] %>
      <h1>Posts</h1>
      <% @posts.each do |post| %>
        <p><b><%= post.title %></b><br /><%= post.body %></p>
      <% end %>

      <h1>Create post</h1>
      <form action="create">
        Title: <input type="text" name="post[title]"><br>
        Body: <textarea name="post[body]"></textarea><br>
        <input type="submit" value="save">
      </form>
      
      </body></html>
    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

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/rails/actionpack/examples/blog_controller.cgi
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/rails/actionpack/examples/blog_controller.cgi
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/rails/actionpack/examples/blog_controller.cgi
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/rails/actionpack/examples/blog_controller.cgi
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/rails/actionpack/examples/blog_controller.cgi
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/rails/actionpack/examples/blog_controller.cgi
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/rails/actionpack/examples/blog_controller.cgi
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/rails/actionpack/examples/blog_controller.cgi
actionpack-1.13.0 examples/blog_controller.cgi
actionpack-1.13.1 examples/blog_controller.cgi
actionpack-1.13.6 examples/blog_controller.cgi
actionpack-1.13.2 examples/blog_controller.cgi
actionpack-1.13.4 examples/blog_controller.cgi
actionpack-1.13.3 examples/blog_controller.cgi
actionpack-1.13.5 examples/blog_controller.cgi
radiant-0.6.1 vendor/rails/actionpack/examples/blog_controller.cgi
radiant-0.6.0 vendor/rails/actionpack/examples/blog_controller.cgi
radiant-0.6.3 vendor/rails/actionpack/examples/blog_controller.cgi
radiant-0.6.2 vendor/rails/actionpack/examples/blog_controller.cgi
radiant-0.6.4 vendor/rails/actionpack/examples/blog_controller.cgi