diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-09 17:55:26 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-09-09 17:55:26 +0000 |
commit | 955fa6151aabfbe0626c84005cb0cad27da3e5c3 (patch) | |
tree | 8d9175f86572bbf00f5e3f021e7b6c7b3804e3f2 /actionpack/examples | |
parent | 73c70836515879f69a152535f3ab411acc3317b8 (diff) | |
download | rails-955fa6151aabfbe0626c84005cb0cad27da3e5c3.tar.gz rails-955fa6151aabfbe0626c84005cb0cad27da3e5c3.tar.bz2 rails-955fa6151aabfbe0626c84005cb0cad27da3e5c3.zip |
The examples are outdated and misleading
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7424 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/examples')
19 files changed, 0 insertions, 455 deletions
diff --git a/actionpack/examples/.htaccess b/actionpack/examples/.htaccess deleted file mode 100644 index fb59fa105e..0000000000 --- a/actionpack/examples/.htaccess +++ /dev/null @@ -1,24 +0,0 @@ -<IfModule mod_ruby.c> - RubyRequire apache/ruby-run - RubySafeLevel 0 - - <Files *.rbx> - SetHandler ruby-object - RubyHandler Apache::RubyRun.instance - </Files> -</IfModule> - - -RewriteEngine On -RewriteRule ^fcgi/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ /$1_controller.fcgi?action=$2&id=$3 [QSA] -RewriteRule ^fcgi/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ /$1_controller.fcgi?action=$2 [QSA] -RewriteRule ^fcgi/([-_a-zA-Z0-9]+)/$ /$1_controller.fcgi?action=index [QSA] - -RewriteRule ^modruby/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ /$1_controller.rbx?action=$2&id=$3 [QSA] -RewriteRule ^modruby/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ /$1_controller.rbx?action=$2 [QSA] -RewriteRule ^modruby/([-_a-zA-Z0-9]+)/$ /$1_controller.rbx?action=index [QSA] - -RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/([0-9]+)$ /$1_controller.cgi?action=$2&id=$3 [QSA] -RewriteRule ^([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)$ /$1_controller.cgi?action=$2 [QSA] -RewriteRule ^([-_a-zA-Z0-9]+)/$ /$1_controller.cgi?action=index [QSA] - diff --git a/actionpack/examples/address_book/index.erb b/actionpack/examples/address_book/index.erb deleted file mode 100644 index 217d39075c..0000000000 --- a/actionpack/examples/address_book/index.erb +++ /dev/null @@ -1,33 +0,0 @@ -<h1>Address Book</h1> - -<% if @people.empty? %> - <p>No people in the address book yet</p> -<% else %> - <table> - <tr><th>Name</th><th>Email Address</th><th>Phone Number</th></tr> - <% for person in @people %> - <tr><td><%= person.name %></td><td><%= person.email_address %></td><td><%= person.phone_number %></td></tr> - <% end %> - </table> -<% end %> - -<form action="create_person"> - <p> - Name:<br /> - <input type="text" name="person[name]"> - </p> - - <p> - Email address:<br /> - <input type="text" name="person[email_address]"> - </p> - - <p> - Phone number:<br /> - <input type="text" name="person[phone_number]"> - </p> - - <p> - <input type="submit" value="Create Person"> - </p> -</form>
\ No newline at end of file diff --git a/actionpack/examples/address_book/index.rhtml b/actionpack/examples/address_book/index.rhtml deleted file mode 100644 index e69de29bb2..0000000000 --- a/actionpack/examples/address_book/index.rhtml +++ /dev/null diff --git a/actionpack/examples/address_book/layout.erb b/actionpack/examples/address_book/layout.erb deleted file mode 100644 index 931e141c01..0000000000 --- a/actionpack/examples/address_book/layout.erb +++ /dev/null @@ -1,8 +0,0 @@ -<html> -<head> - <title><%= @title || "Untitled" %></title> -</head> -<body> -<%= @content_for_layout %> -</body> -</html>
\ No newline at end of file diff --git a/actionpack/examples/address_book/layout.rhtml b/actionpack/examples/address_book/layout.rhtml deleted file mode 100644 index e69de29bb2..0000000000 --- a/actionpack/examples/address_book/layout.rhtml +++ /dev/null diff --git a/actionpack/examples/address_book_controller.cgi b/actionpack/examples/address_book_controller.cgi deleted file mode 100755 index 2e15467285..0000000000 --- a/actionpack/examples/address_book_controller.cgi +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/local/bin/ruby - -require "address_book_controller" - -begin - AddressBookController.process_cgi(CGI.new) -rescue => e - CGI.new.out { "#{e.class}: #{e.message}" } -end
\ No newline at end of file diff --git a/actionpack/examples/address_book_controller.fcgi b/actionpack/examples/address_book_controller.fcgi deleted file mode 100755 index 39947b4444..0000000000 --- a/actionpack/examples/address_book_controller.fcgi +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/local/bin/ruby - -require "address_book_controller" -require "fcgi" - -FCGI.each_cgi { |cgi| AddressBookController.process_cgi(cgi) }
\ No newline at end of file diff --git a/actionpack/examples/address_book_controller.rb b/actionpack/examples/address_book_controller.rb deleted file mode 100644 index 7042ad84a5..0000000000 --- a/actionpack/examples/address_book_controller.rb +++ /dev/null @@ -1,52 +0,0 @@ -$:.unshift(File.dirname(__FILE__) + "/../lib") - -require "action_controller" -require "action_controller/test_process" - -Person = Struct.new("Person", :id, :name, :email_address, :phone_number) - -class AddressBookService - attr_reader :people - - def initialize() @people = [] end - def create_person(data) people.unshift(Person.new(next_person_id, data["name"], data["email_address"], data["phone_number"])) end - def find_person(topic_id) people.select { |person| person.id == person.to_i }.first end - def next_person_id() people.first.id + 1 end -end - -class AddressBookController < ActionController::Base - layout "address_book/layout" - - before_filter :initialize_session_storage - - # Could also have used a proc - # before_filter proc { |c| c.instance_variable_set("@address_book", c.session["address_book"] ||= AddressBookService.new) } - - def index - @title = "Address Book" - @people = @address_book.people - end - - def person - @person = @address_book.find_person(params[:id]) - end - - def create_person - @address_book.create_person(params[:person]) - redirect_to :action => "index" - end - - private - def initialize_session_storage - @address_book = @session["address_book"] ||= AddressBookService.new - end -end - -ActionController::Base.view_paths = [ File.dirname(__FILE__) ] -# ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir - -begin - AddressBookController.process_cgi(CGI.new) if $0 == __FILE__ -rescue => e - CGI.new.out { "#{e.class}: #{e.message}" } -end diff --git a/actionpack/examples/address_book_controller.rbx b/actionpack/examples/address_book_controller.rbx deleted file mode 100644 index 8c04eeccc8..0000000000 --- a/actionpack/examples/address_book_controller.rbx +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/local/bin/ruby - -require "address_book_controller" -AddressBookController.process_cgi(CGI.new)
\ No newline at end of file diff --git a/actionpack/examples/benchmark.rb b/actionpack/examples/benchmark.rb deleted file mode 100644 index 78a6649c74..0000000000 --- a/actionpack/examples/benchmark.rb +++ /dev/null @@ -1,52 +0,0 @@ -$:.unshift(File.dirname(__FILE__) + "/../lib") - -require "action_controller" -require 'action_controller/test_process' - -Person = Struct.new("Person", :name, :address, :age) - -class BenchmarkController < ActionController::Base - def message - render :text => "hello world" - end - - def list - @people = [ Person.new("David"), Person.new("Mary") ] - render_template "hello: <% for person in @people %>Name: <%= person.name %><% end %>" - end - - def form_helper - @person = Person.new "david", "hyacintvej", 24 - render_template( - "<% person = Person.new 'Mary', 'hyacintvej', 22 %> " + - "change the name <%= text_field 'person', 'name' %> and <%= text_field 'person', 'address' %> and <%= text_field 'person', 'age' %>" - ) - end -end - -#ActionController::Base.view_paths = [ File.dirname(__FILE__) ] - -require "benchmark" - -RUNS = ARGV[0] ? ARGV[0].to_i : 50 - -require "profile" if ARGV[1] - -runtime = Benchmark.measure { - RUNS.times { BenchmarkController.process_test(ActionController::TestRequest.new({ "action" => "list" })) } -} - -puts "List: #{RUNS / runtime.real}" - - -runtime = Benchmark.measure { - RUNS.times { BenchmarkController.process_test(ActionController::TestRequest.new({ "action" => "message" })) } -} - -puts "Message: #{RUNS / runtime.real}" - -runtime = Benchmark.measure { - RUNS.times { BenchmarkController.process_test(ActionController::TestRequest.new({ "action" => "form_helper" })) } -} - -puts "Form helper: #{RUNS / runtime.real}" diff --git a/actionpack/examples/benchmark_with_ar.fcgi b/actionpack/examples/benchmark_with_ar.fcgi deleted file mode 100755 index b9de370e24..0000000000 --- a/actionpack/examples/benchmark_with_ar.fcgi +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/local/bin/ruby - -begin - -$:.unshift(File.dirname(__FILE__) + "/../lib") -$:.unshift(File.dirname(__FILE__) + "/../../../edge/activerecord/lib") - -require 'fcgi' -require 'action_controller' -require 'action_controller/test_process' - -require 'active_record' - -class Post < ActiveRecord::Base; end - -ActiveRecord::Base.establish_connection(:adapter => "mysql", :database => "basecamp") - -SESSION_OPTIONS = { "database_manager" => CGI::Session::MemoryStore } - -class TestController < ActionController::Base - def index - render_template <<-EOT - <% for post in Post.find_all(nil,nil,100) %> - <%= post.title %> - <% end %> - EOT - end - - def show_one - render_template <<-EOT - <%= Post.find_first.title %> - EOT - end - - def text - render_text "hello world" - end - - def erb_text - render_template "hello <%= 'world' %>" - end - - def erb_loop - render_template <<-EOT - <% for post in 1..100 %> - <%= post %> - <% end %> - EOT - end - - def rescue_action(e) puts e.message + e.backtrace.join("\n") end -end - -if ARGV.empty? && ENV["REQUEST_URI"] - FCGI.each_cgi do |cgi| - TestController.process(ActionController::CgiRequest.new(cgi, SESSION_OPTIONS), ActionController::CgiResponse.new(cgi)).out - end -else - if ARGV.empty? - cgi = CGI.new - end - - require 'benchmark' - require 'profile' if ARGV[2] == "profile" - - RUNS = ARGV[1] ? ARGV[1].to_i : 50 - - runtime = Benchmark::measure { - RUNS.times { - if ARGV.empty? - TestController.process(ActionController::CgiRequest.new(cgi, SESSION_OPTIONS), ActionController::CgiResponse.new(cgi)) - else - response = TestController.process_test( - ActionController::TestRequest.new({"action" => ARGV[0]}) - ) - puts(response.body) if ARGV[2] == "show" - end - } - } - - puts "Runs: #{RUNS}" - puts "Avg. runtime: #{runtime.real / RUNS}" - puts "Requests/second: #{RUNS / runtime.real}" -end - -rescue Exception => e - # CGI.new.out { "<pre>" + e.message + e.backtrace.join("\n") + "</pre>" } - $stderr << e.message + e.backtrace.join("\n") -end
\ No newline at end of file diff --git a/actionpack/examples/blog_controller.cgi b/actionpack/examples/blog_controller.cgi deleted file mode 100755 index 506afad62f..0000000000 --- a/actionpack/examples/blog_controller.cgi +++ /dev/null @@ -1,53 +0,0 @@ -#!/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.view_paths = [ 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 diff --git a/actionpack/examples/debate/index.erb b/actionpack/examples/debate/index.erb deleted file mode 100644 index ddaa87da57..0000000000 --- a/actionpack/examples/debate/index.erb +++ /dev/null @@ -1,14 +0,0 @@ -<html> -<body> -<h1>Topics</h1> - -<%= link_to "New topic", :action => "new_topic" %> - -<ul> -<% for topic in @topics %> - <li><%= link_to "#{topic.title} (#{topic.replies.length} replies)", :action => "topic", :path_params => { "id" => topic.id } %></li> -<% end %> -</ul> - -</body> -</html>
\ No newline at end of file diff --git a/actionpack/examples/debate/index.rhtml b/actionpack/examples/debate/index.rhtml deleted file mode 100644 index e69de29bb2..0000000000 --- a/actionpack/examples/debate/index.rhtml +++ /dev/null diff --git a/actionpack/examples/debate/new_topic.erb b/actionpack/examples/debate/new_topic.erb deleted file mode 100644 index f52a69cc31..0000000000 --- a/actionpack/examples/debate/new_topic.erb +++ /dev/null @@ -1,22 +0,0 @@ -<html> -<body> -<h1>New topic</h1> - -<form action="<%= url_for(:action => "create_topic") %>" method="post"> - <p> - Title:<br> - <input type="text" name="topic[title]"> - </p> - - <p> - Body:<br> - <textarea name="topic[body]" style="width: 200px; height: 200px"></textarea> - </p> - - <p> - <input type="submit" value="Create topic"> - </p> -</form> - -</body> -</html>
\ No newline at end of file diff --git a/actionpack/examples/debate/new_topic.rhtml b/actionpack/examples/debate/new_topic.rhtml deleted file mode 100644 index e69de29bb2..0000000000 --- a/actionpack/examples/debate/new_topic.rhtml +++ /dev/null diff --git a/actionpack/examples/debate/topic.erb b/actionpack/examples/debate/topic.erb deleted file mode 100644 index e247c00f0d..0000000000 --- a/actionpack/examples/debate/topic.erb +++ /dev/null @@ -1,32 +0,0 @@ -<html> -<body> -<h1><%= @topic.title %></h1> - -<p><%= @topic.body %></p> - -<%= link_to "Back to topics", :action => "index" %> - -<% unless @topic.replies.empty? %> - <h2>Replies</h2> - <ol> - <% for reply in @topic.replies %> - <li><%= reply.body %></li> - <% end %> - </ol> -<% end %> - -<h2>Reply to this topic</h2> - -<form action="<%= url_for(:action => "create_reply") %>" method="post"> - <input type="hidden" name="reply[topic_id]" value="<%= @topic.id %>"> - <p> - <textarea name="reply[body]" style="width: 200px; height: 200px"></textarea> - </p> - - <p> - <input type="submit" value="Create reply"> - </p> -</form> - -</body> -</html>
\ No newline at end of file diff --git a/actionpack/examples/debate/topic.rhtml b/actionpack/examples/debate/topic.rhtml deleted file mode 100644 index e69de29bb2..0000000000 --- a/actionpack/examples/debate/topic.rhtml +++ /dev/null diff --git a/actionpack/examples/debate_controller.cgi b/actionpack/examples/debate_controller.cgi deleted file mode 100755 index 9cb787940c..0000000000 --- a/actionpack/examples/debate_controller.cgi +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/local/bin/ruby - -$:.unshift(File.dirname(__FILE__) + "/../lib") - -require "action_controller" - -Topic = Struct.new("Topic", :id, :title, :body, :replies) -Reply = Struct.new("Reply", :body) - -class DebateService - attr_reader :topics - - def initialize() @topics = [] end - def create_topic(data) topics.unshift(Topic.new(next_topic_id, data["title"], data["body"], [])) end - def create_reply(data) find_topic(data["topic_id"]).replies << Reply.new(data["body"]) end - def find_topic(topic_id) topics.select { |topic| topic.id == topic_id.to_i }.first end - def next_topic_id() topics.first.id + 1 end -end - -class DebateController < ActionController::Base - before_filter :initialize_session_storage - - def index - @topics = @debate.topics - end - - def topic - @topic = @debate.find_topic(params[:id]) - end - - # def new_topic() end <-- This is not needed as the template doesn't require any assigns - - def create_topic - @debate.create_topic(params[:topic]) - redirect_to :action => "index" - end - - def create_reply - @debate.create_reply(params[:reply]) - redirect_to :action => "topic", :path_params => { "id" => params[:reply][:topic_id] } - end - - private - def initialize_session_storage - @session["debate"] = DebateService.new if @session["debate"].nil? - @debate = @session["debate"] - end -end - -ActionController::Base.view_paths = [ File.dirname(__FILE__) ] -# ActionController::Base.logger = Logger.new("debug.log") # Remove first comment to turn on logging in current dir - -begin - DebateController.process_cgi(CGI.new) if $0 == __FILE__ -rescue => e - CGI.new.out { "#{e.class}: #{e.message}" } -end |