Permalink
Browse files

automatic import from ryanb/railscasts-episodes

  • Loading branch information...
0 parents commit 957ecce12f7535ce06cccf0a9de48192f812e259 @gilesbowkett gilesbowkett committed Jul 29, 2011
Showing with 8,253 additions and 0 deletions.
  1. +3 −0 README
  2. +3 −0 store/.gitignore
  3. +1 −0 store/README
  4. +10 −0 store/Rakefile
  5. +10 −0 store/app/controllers/application_controller.rb
  6. +38 −0 store/app/controllers/orders_controller.rb
  7. +3 −0 store/app/helpers/application_helper.rb
  8. +22 −0 store/app/helpers/layout_helper.rb
  9. +2 −0 store/app/helpers/orders_helper.rb
  10. +38 −0 store/app/models/order.rb
  11. +22 −0 store/app/views/layouts/application.html.erb
  12. +5 −0 store/app/views/orders/_billing_step.html.erb
  13. +9 −0 store/app/views/orders/_confirmation_step.html.erb
  14. +5 −0 store/app/views/orders/_shipping_step.html.erb
  15. +17 −0 store/app/views/orders/index.html.erb
  16. +11 −0 store/app/views/orders/new.html.erb
  17. +14 −0 store/app/views/orders/show.html.erb
  18. +110 −0 store/config/boot.rb
  19. +22 −0 store/config/database.yml
  20. +41 −0 store/config/environment.rb
  21. +17 −0 store/config/environments/development.rb
  22. +28 −0 store/config/environments/production.rb
  23. +28 −0 store/config/environments/test.rb
  24. +7 −0 store/config/initializers/backtrace_silencers.rb
  25. +10 −0 store/config/initializers/inflections.rb
  26. +5 −0 store/config/initializers/mime_types.rb
  27. +21 −0 store/config/initializers/new_rails_defaults.rb
  28. +15 −0 store/config/initializers/session_store.rb
  29. +5 −0 store/config/locales/en.yml
  30. +4 −0 store/config/routes.rb
  31. +13 −0 store/db/migrate/20100606013839_create_orders.rb
  32. +21 −0 store/db/schema.rb
  33. +7 −0 store/db/seeds.rb
  34. +2 −0 store/doc/README_FOR_APP
  35. 0 store/log/.gitignore
  36. +30 −0 store/public/404.html
  37. +30 −0 store/public/422.html
  38. +30 −0 store/public/500.html
  39. 0 store/public/favicon.ico
  40. BIN store/public/images/rails.png
  41. +2 −0 store/public/javascripts/application.js
  42. +963 −0 store/public/javascripts/controls.js
  43. +973 −0 store/public/javascripts/dragdrop.js
  44. +1,128 −0 store/public/javascripts/effects.js
  45. +4,320 −0 store/public/javascripts/prototype.js
  46. +5 −0 store/public/robots.txt
  47. +81 −0 store/public/stylesheets/application.css
  48. +4 −0 store/script/about
  49. +3 −0 store/script/console
  50. +3 −0 store/script/dbconsole
  51. +3 −0 store/script/destroy
  52. +3 −0 store/script/generate
  53. +3 −0 store/script/performance/benchmarker
  54. +3 −0 store/script/performance/profiler
  55. +3 −0 store/script/plugin
  56. +3 −0 store/script/runner
  57. +3 −0 store/script/server
  58. +7 −0 store/test/fixtures/orders.yml
  59. +30 −0 store/test/functional/orders_controller_test.rb
  60. +9 −0 store/test/performance/browsing_test.rb
  61. +38 −0 store/test/test_helper.rb
  62. +7 −0 store/test/unit/order_test.rb
  63. 0 store/tmp/.gitignore
3 README
@@ -0,0 +1,3 @@
+Railscasts Episode #217: Multistep Forms
+
+http://railscasts.com/episodes/217
@@ -0,0 +1,3 @@
+*.sqlite3
+log/*.log
+tmp/**/*
@@ -0,0 +1 @@
+Railscasts example application.
@@ -0,0 +1,10 @@
+# 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.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
@@ -0,0 +1,10 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
+
+ # Scrub sensitive parameters from your log
+ # filter_parameter_logging :password
+end
@@ -0,0 +1,38 @@
+class OrdersController < ApplicationController
+ def index
+ @orders = Order.all
+ end
+
+ def show
+ @order = Order.find(params[:id])
+ end
+
+ def new
+ session[:order_params] ||= {}
+ @order = Order.new(session[:order_params])
+ @order.current_step = session[:order_step]
+ end
+
+ def create
+ session[:order_params].deep_merge!(params[:order]) if params[:order]
+ @order = Order.new(session[:order_params])
+ @order.current_step = session[:order_step]
+ if @order.valid?
+ if params[:back_button]
+ @order.previous_step
+ elsif @order.last_step?
+ @order.save if @order.all_valid?
+ else
+ @order.next_step
+ end
+ session[:order_step] = @order.current_step
+ end
+ if @order.new_record?
+ render "new"
+ else
+ session[:order_step] = session[:order_params] = nil
+ flash[:notice] = "Order saved!"
+ redirect_to @order
+ end
+ end
+end
@@ -0,0 +1,3 @@
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+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 OrdersHelper
+end
@@ -0,0 +1,38 @@
+class Order < ActiveRecord::Base
+ attr_accessible :shipping_name, :billing_name
+ attr_writer :current_step
+
+ validates_presence_of :shipping_name, :if => lambda { |o| o.current_step == "shipping" }
+ validates_presence_of :billing_name, :if => lambda { |o| o.current_step == "billing" }
+
+ def current_step
+ @current_step || steps.first
+ end
+
+ def steps
+ %w[shipping billing confirmation]
+ end
+
+ def next_step
+ self.current_step = steps[steps.index(current_step)+1]
+ end
+
+ def previous_step
+ self.current_step = steps[steps.index(current_step)-1]
+ end
+
+ def first_step?
+ current_step == steps.first
+ end
+
+ def last_step?
+ current_step == steps.last
+ end
+
+ def all_valid?
+ steps.all? do |step|
+ self.current_step = step
+ valid?
+ end
+ end
+end
@@ -0,0 +1,22 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title><%= h(yield(:title) || "Untitled") %></title>
+ <%= stylesheet_link_tag 'application' %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <%- flash.each do |name, msg| -%>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <%- end -%>
+
+ <%- if show_title? -%>
+ <h1><%=h yield(:title) %></h1>
+ <%- end -%>
+
+ <%= yield %>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,5 @@
+ <h2>Billing Information</h2>
+ <p>
+ <%= f.label :billing_name %><br />
+ <%= f.text_field :billing_name %>
+ </p>
@@ -0,0 +1,9 @@
+ <h2>Confirm Information</h2>
+ <p>
+ <strong>Shipping Name:</strong>
+ <%=h @order.shipping_name %>
+ </p>
+ <p>
+ <strong>Billing Name:</strong>
+ <%=h @order.billing_name %>
+ </p>
@@ -0,0 +1,5 @@
+ <h2>Shipping Information</h2>
+ <p>
+ <%= f.label :shipping_name %><br />
+ <%= f.text_field :shipping_name %>
+ </p>
@@ -0,0 +1,17 @@
+<% title "Orders" %>
+
+<table>
+ <tr>
+ <th>Shipping Name</th>
+ <th>Billing Name</th>
+ </tr>
+ <% for order in @orders %>
+ <tr>
+ <td><%=h order.shipping_name %></td>
+ <td><%=h order.billing_name %></td>
+ <td><%= link_to "Show", order %></td>
+ </tr>
+ <% end %>
+</table>
+
+<p><%= link_to "New Order", new_order_path %></p>
@@ -0,0 +1,11 @@
+<% title "New Order" %>
+
+<% form_for @order do |f| %>
+ <%= f.error_messages %>
+ <%= render "#{@order.current_step}_step", :f => f %>
+ <p><%= f.submit "Continue" %></p>
+ <p><%= f.submit "Back", :name => "back_button" unless @order.first_step? %></p>
+<% end %>
+
+
+<p><%= link_to "Back to List", orders_path %></p>
@@ -0,0 +1,14 @@
+<% title "Order" %>
+
+<p>
+ <strong>Shipping Name:</strong>
+ <%=h @order.shipping_name %>
+</p>
+<p>
+ <strong>Billing Name:</strong>
+ <%=h @order.billing_name %>
+</p>
+
+<p>
+ <%= link_to "View All", orders_path %>
+</p>
@@ -0,0 +1,110 @@
+# Don't change this file!
+# Configure your app in config/environment.rb and config/environments/*.rb
+
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
+
+module Rails
+ class << self
+ def boot!
+ unless booted?
+ preinitialize
+ pick_boot.run
+ end
+ end
+
+ def booted?
+ defined? Rails::Initializer
+ end
+
+ def pick_boot
+ (vendor_rails? ? VendorBoot : GemBoot).new
+ end
+
+ def vendor_rails?
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
+ end
+
+ def preinitialize
+ load(preinitializer_path) if File.exist?(preinitializer_path)
+ end
+
+ def preinitializer_path
+ "#{RAILS_ROOT}/config/preinitializer.rb"
+ end
+ end
+
+ class Boot
+ def run
+ load_initializer
+ Rails::Initializer.run(:set_load_path)
+ end
+ end
+
+ class VendorBoot < Boot
+ def load_initializer
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
+ Rails::Initializer.run(:install_gem_spec_stubs)
+ Rails::GemDependency.add_frozen_gem_path
+ end
+ end
+
+ class GemBoot < Boot
+ def load_initializer
+ self.class.load_rubygems
+ load_rails_gem
+ require 'initializer'
+ end
+
+ def load_rails_gem
+ if version = self.class.gem_version
+ gem 'rails', version
+ else
+ gem 'rails'
+ end
+ rescue Gem::LoadError => load_error
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
+ exit 1
+ end
+
+ class << self
+ def rubygems_version
+ Gem::RubyGemsVersion rescue nil
+ end
+
+ def gem_version
+ if defined? RAILS_GEM_VERSION
+ RAILS_GEM_VERSION
+ elsif ENV.include?('RAILS_GEM_VERSION')
+ ENV['RAILS_GEM_VERSION']
+ else
+ parse_gem_version(read_environment_rb)
+ end
+ end
+
+ def load_rubygems
+ min_version = '1.3.2'
+ require 'rubygems'
+ unless rubygems_version >= min_version
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
+ exit 1
+ end
+
+ rescue LoadError
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
+ exit 1
+ end
+
+ def parse_gem_version(text)
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
+ end
+
+ private
+ def read_environment_rb
+ File.read("#{RAILS_ROOT}/config/environment.rb")
+ end
+ end
+ end
+end
+
+# All that for this:
+Rails.boot!
@@ -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
Oops, something went wrong.

0 comments on commit 957ecce

Please sign in to comment.