Permalink
Browse files

adding episode 222

  • Loading branch information...
1 parent 05fabba commit 73e1f6e51ffd3da9688c5cd099a291fd2c277a06 @ryanb committed Jul 12, 2010
Showing with 8,937 additions and 0 deletions.
  1. +3 −0 episode-222/README
  2. +4 −0 episode-222/store/.gitignore
  3. +32 −0 episode-222/store/Gemfile
  4. +1 −0 episode-222/store/README
  5. +7 −0 episode-222/store/Rakefile
  6. +4 −0 episode-222/store/app/controllers/application_controller.rb
  7. +5 −0 episode-222/store/app/controllers/home_controller.rb
  8. +4 −0 episode-222/store/app/controllers/info_controller.rb
  9. +44 −0 episode-222/store/app/controllers/products_controller.rb
  10. +2 −0 episode-222/store/app/helpers/application_helper.rb
  11. +23 −0 episode-222/store/app/helpers/error_messages_helper.rb
  12. +2 −0 episode-222/store/app/helpers/home_helper.rb
  13. +2 −0 episode-222/store/app/helpers/info_helper.rb
  14. +22 −0 episode-222/store/app/helpers/layout_helper.rb
  15. +2 −0 episode-222/store/app/helpers/products_helper.rb
  16. +3 −0 episode-222/store/app/models/product.rb
  17. +3 −0 episode-222/store/app/views/home/index.html.erb
  18. +3 −0 episode-222/store/app/views/info/about.html.erb
  19. +19 −0 episode-222/store/app/views/layouts/application.html.erb
  20. +2 −0 episode-222/store/app/views/processes_app/index.html.erb
  21. +12 −0 episode-222/store/app/views/products/_form.html.erb
  22. +8 −0 episode-222/store/app/views/products/edit.html.erb
  23. +19 −0 episode-222/store/app/views/products/index.html.erb
  24. +5 −0 episode-222/store/app/views/products/new.html.erb
  25. +16 −0 episode-222/store/app/views/products/show.html.erb
  26. +4 −0 episode-222/store/config.ru
  27. +46 −0 episode-222/store/config/application.rb
  28. +13 −0 episode-222/store/config/boot.rb
  29. +22 −0 episode-222/store/config/database.yml
  30. +5 −0 episode-222/store/config/environment.rb
  31. +19 −0 episode-222/store/config/environments/development.rb
  32. +46 −0 episode-222/store/config/environments/production.rb
  33. +32 −0 episode-222/store/config/environments/test.rb
  34. +7 −0 episode-222/store/config/initializers/backtrace_silencers.rb
  35. +10 −0 episode-222/store/config/initializers/inflections.rb
  36. +5 −0 episode-222/store/config/initializers/mime_types.rb
  37. +7 −0 episode-222/store/config/initializers/secret_token.rb
  38. +8 −0 episode-222/store/config/initializers/session_store.rb
  39. +5 −0 episode-222/store/config/locales/en.yml
  40. +11 −0 episode-222/store/config/routes.rb
  41. +13 −0 episode-222/store/db/migrate/20100712065243_create_products.rb
  42. +21 −0 episode-222/store/db/schema.rb
  43. +7 −0 episode-222/store/db/seeds.rb
  44. +2 −0 episode-222/store/doc/README_FOR_APP
  45. +5 −0 episode-222/store/lib/home_app.rb
  46. +10 −0 episode-222/store/lib/processes_app.rb
  47. 0 episode-222/store/lib/tasks/.gitkeep
  48. +26 −0 episode-222/store/public/404.html
  49. +26 −0 episode-222/store/public/422.html
  50. +26 −0 episode-222/store/public/500.html
  51. 0 episode-222/store/public/favicon.ico
  52. BIN episode-222/store/public/images/rails.png
  53. +2 −0 episode-222/store/public/javascripts/application.js
  54. +965 −0 episode-222/store/public/javascripts/controls.js
  55. +974 −0 episode-222/store/public/javascripts/dragdrop.js
  56. +1,123 −0 episode-222/store/public/javascripts/effects.js
  57. +4,874 −0 episode-222/store/public/javascripts/prototype.js
  58. +118 −0 episode-222/store/public/javascripts/rails.js
  59. +5 −0 episode-222/store/public/robots.txt
  60. 0 episode-222/store/public/stylesheets/.gitkeep
  61. +75 −0 episode-222/store/public/stylesheets/application.css
  62. +56 −0 episode-222/store/public/stylesheets/scaffold.css
  63. +6 −0 episode-222/store/script/rails
  64. +7 −0 episode-222/store/test/fixtures/products.yml
  65. +9 −0 episode-222/store/test/functional/home_controller_test.rb
  66. +9 −0 episode-222/store/test/functional/info_controller_test.rb
  67. +54 −0 episode-222/store/test/functional/products_controller_test.rb
  68. +9 −0 episode-222/store/test/performance/browsing_test.rb
  69. +13 −0 episode-222/store/test/test_helper.rb
  70. +4 −0 episode-222/store/test/unit/helpers/home_helper_test.rb
  71. +4 −0 episode-222/store/test/unit/helpers/info_helper_test.rb
  72. +7 −0 episode-222/store/test/unit/product_test.rb
  73. 0 episode-222/store/vendor/plugins/.gitkeep
View
@@ -0,0 +1,3 @@
+Railscasts Episode #222: Rack in Rails 3
+
+http://railscasts.com/episodes/222
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
@@ -0,0 +1,32 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.0.beta4'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
+gem 'nifty-generators'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri', '1.4.1'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for certain environments:
+# gem 'rspec', :group => :test
+# group :test do
+# gem 'webrat'
+# end
+
+gem "sinatra"
@@ -0,0 +1 @@
+Example application used in Railscasts.
@@ -0,0 +1,7 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+Rails::Application.load_tasks
@@ -0,0 +1,4 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+ layout 'application'
+end
@@ -0,0 +1,5 @@
+class HomeController < ApplicationController
+ def index
+ end
+
+end
@@ -0,0 +1,4 @@
+class InfoController < ApplicationController
+ def about
+ end
+end
@@ -0,0 +1,44 @@
+class ProductsController < ApplicationController
+ def index
+ @products = Product.all
+ end
+
+ def show
+ @product = Product.find(params[:id])
+ end
+
+ def new
+ @product = Product.new
+ end
+
+ def create
+ @product = Product.new(params[:product])
+ if @product.save
+ flash[:notice] = "Successfully created product."
+ redirect_to @product
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @product = Product.find(params[:id])
+ end
+
+ def update
+ @product = Product.find(params[:id])
+ if @product.update_attributes(params[:product])
+ flash[:notice] = "Successfully updated product."
+ redirect_to @product
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @product = Product.find(params[:id])
+ @product.destroy
+ flash[:notice] = "Successfully destroyed product."
+ redirect_to products_url
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,23 @@
+module ErrorMessagesHelper
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
+ def error_messages_for(*objects)
+ options = objects.extract_options!
+ options[:header_message] ||= "Invalid Fields"
+ options[:message] ||= "Correct the following errors and try again."
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
+ unless messages.empty?
+ content_tag(:div, :class => "error_messages") do
+ list_items = messages.map { |msg| content_tag(:li, msg) }
+ content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
+ end
+ end
+ end
+
+ module FormBuilderAdditions
+ def error_messages(options = {})
+ @template.error_messages_for(@object, options)
+ end
+ end
+end
+
+ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -0,0 +1,2 @@
+module HomeHelper
+end
@@ -0,0 +1,2 @@
+module InfoHelper
+end
@@ -0,0 +1,22 @@
+# These helper methods can be called in your template to set variables to be used in the layout
+# This module should be included in all views globally,
+# to do so you may need to add this line to your ApplicationController
+# helper :layout
+module LayoutHelper
+ def title(page_title, show_title = true)
+ content_for(:title) { page_title.to_s }
+ @show_title = show_title
+ end
+
+ def show_title?
+ @show_title
+ end
+
+ def stylesheet(*args)
+ content_for(:head) { stylesheet_link_tag(*args) }
+ end
+
+ def javascript(*args)
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+end
@@ -0,0 +1,2 @@
+module ProductsHelper
+end
@@ -0,0 +1,3 @@
+class Product < ActiveRecord::Base
+ attr_accessible :name, :price
+end
@@ -0,0 +1,3 @@
+<% title "Home" %>
+
+<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
@@ -0,0 +1,3 @@
+<% title "About Us" %>
+
+<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%= yield(:title) || "Untitled" %></title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= content_tag :h1, yield(:title) if show_title? %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,2 @@
+<h1>Proccesses</h1>
+<pre><%= @processes %></pre>
@@ -0,0 +1,12 @@
+<%= form_for @product do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :price %><br />
+ <%= f.text_field :price %>
+ </p>
+ <p><%= f.submit %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Product" %>
+
+<%= render 'form' %>
+
+<p>
+ <%= link_to "Show", @product %> |
+ <%= link_to "View All", products_path %>
+</p>
@@ -0,0 +1,19 @@
+<% title "Products" %>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Price</th>
+ </tr>
+ <% for product in @products %>
+ <tr>
+ <td><%= product.name %></td>
+ <td><%= product.price %></td>
+ <td><%= link_to "Show", product %></td>
+ <td><%= link_to "Edit", edit_product_path(product) %></td>
+ <td><%= link_to "Destroy", product, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+ <% end %>
+</table>
+
+<p><%= link_to "New Product", new_product_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Product" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", products_path %></p>
@@ -0,0 +1,16 @@
+<% title "Product" %>
+
+<p>
+ <strong>Name:</strong>
+ <%= @product.name %>
+</p>
+<p>
+ <strong>Price:</strong>
+ <%= @product.price %>
+</p>
+
+<p>
+ <%= link_to "Edit", edit_product_path(@product) %> |
+ <%= link_to "Destroy", @product, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View All", products_path %>
+</p>
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Store::Application
@@ -0,0 +1,46 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module Store
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Add additional load paths for your own custom dirs
+ # config.load_paths += %W( #{config.root}/extras )
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # Configure generators values. Many other options are available, be sure to check the documentation.
+ # config.generators do |g|
+ # g.orm :active_record
+ # g.template_engine :erb
+ # g.test_framework :test_unit, :fixture => true
+ # end
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+ end
+end
@@ -0,0 +1,13 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+gemfile = File.expand_path('../../Gemfile', __FILE__)
+begin
+ ENV['BUNDLE_GEMFILE'] = gemfile
+ require 'bundler'
+ Bundler.setup
+rescue Bundler::GemNotFound => e
+ STDERR.puts e.message
+ STDERR.puts "Try running `bundle install`."
+ exit!
+end if File.exist?(gemfile)
@@ -0,0 +1,22 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Store::Application.initialize!
@@ -0,0 +1,19 @@
+Store::Application.configure do
+ # Settings specified here will take precedence over those in config/environment.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the webserver when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_view.debug_rjs = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+end
Oops, something went wrong. Retry.

0 comments on commit 73e1f6e

Please sign in to comment.