Permalink
Browse files

adding revised episode 153

  • Loading branch information...
1 parent 45fac99 commit 9fa0e0e1a3cadea69a5a4e3ac921f14fa71ea0e0 @ryanb committed Nov 4, 2011
Showing with 1,808 additions and 0 deletions.
  1. +3 −0 episode-153/revised/README
  2. +5 −0 episode-153/revised/store-after/.gitignore
  3. +17 −0 episode-153/revised/store-after/Gemfile
  4. +123 −0 episode-153/revised/store-after/Gemfile.lock
  5. +9 −0 episode-153/revised/store-after/README
  6. +7 −0 episode-153/revised/store-after/Rakefile
  7. BIN episode-153/revised/store-after/app/assets/images/rails.png
  8. +9 −0 episode-153/revised/store-after/app/assets/javascripts/application.js
  9. +3 −0 episode-153/revised/store-after/app/assets/javascripts/orders.js.coffee
  10. +92 −0 episode-153/revised/store-after/app/assets/stylesheets/application.css
  11. +37 −0 episode-153/revised/store-after/app/assets/stylesheets/orders.css.scss
  12. +3 −0 episode-153/revised/store-after/app/controllers/application_controller.rb
  13. +18 −0 episode-153/revised/store-after/app/controllers/orders_controller.rb
  14. +2 −0 episode-153/revised/store-after/app/helpers/application_helper.rb
  15. +2 −0 episode-153/revised/store-after/app/helpers/orders_helper.rb
  16. 0 episode-153/revised/store-after/app/mailers/.gitkeep
  17. 0 episode-153/revised/store-after/app/models/.gitkeep
  18. +7 −0 episode-153/revised/store-after/app/models/line_item.rb
  19. +8 −0 episode-153/revised/store-after/app/models/order.rb
  20. +40 −0 episode-153/revised/store-after/app/pdfs/order_pdf.rb
  21. +17 −0 episode-153/revised/store-after/app/views/layouts/application.html.erb
  22. +6 −0 episode-153/revised/store-after/app/views/orders/index.html.erb
  23. +25 −0 episode-153/revised/store-after/app/views/orders/show.html.erb
  24. +4 −0 episode-153/revised/store-after/config.ru
  25. +48 −0 episode-153/revised/store-after/config/application.rb
  26. +6 −0 episode-153/revised/store-after/config/boot.rb
  27. +25 −0 episode-153/revised/store-after/config/database.yml
  28. +5 −0 episode-153/revised/store-after/config/environment.rb
  29. +30 −0 episode-153/revised/store-after/config/environments/development.rb
  30. +60 −0 episode-153/revised/store-after/config/environments/production.rb
  31. +39 −0 episode-153/revised/store-after/config/environments/test.rb
  32. +7 −0 episode-153/revised/store-after/config/initializers/backtrace_silencers.rb
  33. +10 −0 episode-153/revised/store-after/config/initializers/inflections.rb
  34. +5 −0 episode-153/revised/store-after/config/initializers/mime_types.rb
  35. +7 −0 episode-153/revised/store-after/config/initializers/secret_token.rb
  36. +8 −0 episode-153/revised/store-after/config/initializers/session_store.rb
  37. +14 −0 episode-153/revised/store-after/config/initializers/wrap_parameters.rb
  38. +5 −0 episode-153/revised/store-after/config/locales/en.yml
  39. +4 −0 episode-153/revised/store-after/config/routes.rb
  40. +9 −0 episode-153/revised/store-after/db/migrate/20111103182049_create_orders.rb
  41. +12 −0 episode-153/revised/store-after/db/migrate/20111103182140_create_line_items.rb
  42. +31 −0 episode-153/revised/store-after/db/schema.rb
  43. +6 −0 episode-153/revised/store-after/db/seeds.rb
  44. +2 −0 episode-153/revised/store-after/doc/README_FOR_APP
  45. 0 episode-153/revised/store-after/lib/assets/.gitkeep
  46. 0 episode-153/revised/store-after/lib/tasks/.gitkeep
  47. 0 episode-153/revised/store-after/log/.gitkeep
  48. +26 −0 episode-153/revised/store-after/public/404.html
  49. +26 −0 episode-153/revised/store-after/public/422.html
  50. +26 −0 episode-153/revised/store-after/public/500.html
  51. 0 episode-153/revised/store-after/public/favicon.ico
  52. +5 −0 episode-153/revised/store-after/public/robots.txt
  53. +6 −0 episode-153/revised/store-after/script/rails
  54. 0 episode-153/revised/store-after/test/fixtures/.gitkeep
  55. +13 −0 episode-153/revised/store-after/test/fixtures/line_items.yml
  56. +7 −0 episode-153/revised/store-after/test/fixtures/orders.yml
  57. 0 episode-153/revised/store-after/test/functional/.gitkeep
  58. +14 −0 episode-153/revised/store-after/test/functional/orders_controller_test.rb
  59. 0 episode-153/revised/store-after/test/integration/.gitkeep
  60. +12 −0 episode-153/revised/store-after/test/performance/browsing_test.rb
  61. +13 −0 episode-153/revised/store-after/test/test_helper.rb
  62. 0 episode-153/revised/store-after/test/unit/.gitkeep
  63. +4 −0 episode-153/revised/store-after/test/unit/helpers/orders_helper_test.rb
  64. +7 −0 episode-153/revised/store-after/test/unit/line_item_test.rb
  65. +7 −0 episode-153/revised/store-after/test/unit/order_test.rb
  66. 0 episode-153/revised/store-after/vendor/assets/stylesheets/.gitkeep
  67. 0 episode-153/revised/store-after/vendor/plugins/.gitkeep
  68. +5 −0 episode-153/revised/store-before/.gitignore
  69. +15 −0 episode-153/revised/store-before/Gemfile
  70. +115 −0 episode-153/revised/store-before/Gemfile.lock
  71. +9 −0 episode-153/revised/store-before/README
  72. +7 −0 episode-153/revised/store-before/Rakefile
  73. BIN episode-153/revised/store-before/app/assets/images/rails.png
  74. +9 −0 episode-153/revised/store-before/app/assets/javascripts/application.js
  75. +3 −0 episode-153/revised/store-before/app/assets/javascripts/orders.js.coffee
  76. +92 −0 episode-153/revised/store-before/app/assets/stylesheets/application.css
  77. +37 −0 episode-153/revised/store-before/app/assets/stylesheets/orders.css.scss
  78. +3 −0 episode-153/revised/store-before/app/controllers/application_controller.rb
  79. +9 −0 episode-153/revised/store-before/app/controllers/orders_controller.rb
  80. +2 −0 episode-153/revised/store-before/app/helpers/application_helper.rb
  81. +2 −0 episode-153/revised/store-before/app/helpers/orders_helper.rb
  82. 0 episode-153/revised/store-before/app/mailers/.gitkeep
  83. 0 episode-153/revised/store-before/app/models/.gitkeep
  84. +7 −0 episode-153/revised/store-before/app/models/line_item.rb
  85. +8 −0 episode-153/revised/store-before/app/models/order.rb
  86. +17 −0 episode-153/revised/store-before/app/views/layouts/application.html.erb
  87. +6 −0 episode-153/revised/store-before/app/views/orders/index.html.erb
  88. +23 −0 episode-153/revised/store-before/app/views/orders/show.html.erb
  89. +4 −0 episode-153/revised/store-before/config.ru
  90. +48 −0 episode-153/revised/store-before/config/application.rb
  91. +6 −0 episode-153/revised/store-before/config/boot.rb
  92. +25 −0 episode-153/revised/store-before/config/database.yml
  93. +5 −0 episode-153/revised/store-before/config/environment.rb
  94. +30 −0 episode-153/revised/store-before/config/environments/development.rb
  95. +60 −0 episode-153/revised/store-before/config/environments/production.rb
  96. +39 −0 episode-153/revised/store-before/config/environments/test.rb
  97. +7 −0 episode-153/revised/store-before/config/initializers/backtrace_silencers.rb
  98. +10 −0 episode-153/revised/store-before/config/initializers/inflections.rb
  99. +5 −0 episode-153/revised/store-before/config/initializers/mime_types.rb
  100. +7 −0 episode-153/revised/store-before/config/initializers/secret_token.rb
  101. +8 −0 episode-153/revised/store-before/config/initializers/session_store.rb
  102. +14 −0 episode-153/revised/store-before/config/initializers/wrap_parameters.rb
  103. +5 −0 episode-153/revised/store-before/config/locales/en.yml
  104. +4 −0 episode-153/revised/store-before/config/routes.rb
  105. +9 −0 episode-153/revised/store-before/db/migrate/20111103182049_create_orders.rb
  106. +12 −0 episode-153/revised/store-before/db/migrate/20111103182140_create_line_items.rb
  107. +31 −0 episode-153/revised/store-before/db/schema.rb
  108. +6 −0 episode-153/revised/store-before/db/seeds.rb
  109. +2 −0 episode-153/revised/store-before/doc/README_FOR_APP
  110. 0 episode-153/revised/store-before/lib/assets/.gitkeep
  111. 0 episode-153/revised/store-before/lib/tasks/.gitkeep
  112. 0 episode-153/revised/store-before/log/.gitkeep
  113. +26 −0 episode-153/revised/store-before/public/404.html
  114. +26 −0 episode-153/revised/store-before/public/422.html
  115. +26 −0 episode-153/revised/store-before/public/500.html
  116. 0 episode-153/revised/store-before/public/favicon.ico
  117. +5 −0 episode-153/revised/store-before/public/robots.txt
  118. +6 −0 episode-153/revised/store-before/script/rails
  119. 0 episode-153/revised/store-before/test/fixtures/.gitkeep
  120. +13 −0 episode-153/revised/store-before/test/fixtures/line_items.yml
  121. +7 −0 episode-153/revised/store-before/test/fixtures/orders.yml
  122. 0 episode-153/revised/store-before/test/functional/.gitkeep
  123. +14 −0 episode-153/revised/store-before/test/functional/orders_controller_test.rb
  124. 0 episode-153/revised/store-before/test/integration/.gitkeep
  125. +12 −0 episode-153/revised/store-before/test/performance/browsing_test.rb
  126. +13 −0 episode-153/revised/store-before/test/test_helper.rb
  127. 0 episode-153/revised/store-before/test/unit/.gitkeep
  128. +4 −0 episode-153/revised/store-before/test/unit/helpers/orders_helper_test.rb
  129. +7 −0 episode-153/revised/store-before/test/unit/line_item_test.rb
  130. +7 −0 episode-153/revised/store-before/test/unit/order_test.rb
  131. 0 episode-153/revised/store-before/vendor/assets/stylesheets/.gitkeep
  132. 0 episode-153/revised/store-before/vendor/plugins/.gitkeep
@@ -0,0 +1,3 @@
+RailsCasts Episode #153: PDFs with Prawn (revised)
+
+http://railscasts.com/episodes/153-pdfs-with-prawn-revised
@@ -0,0 +1,5 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
+.sass-cache/
@@ -0,0 +1,17 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.1.1'
+
+gem 'sqlite3'
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', '~> 3.1.4'
+ gem 'coffee-rails', '~> 3.1.1'
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+
+gem 'prawn'
@@ -0,0 +1,123 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ Ascii85 (1.0.1)
+ actionmailer (3.1.1)
+ actionpack (= 3.1.1)
+ mail (~> 2.3.0)
+ actionpack (3.1.1)
+ activemodel (= 3.1.1)
+ activesupport (= 3.1.1)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.2)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.2)
+ activemodel (3.1.1)
+ activesupport (= 3.1.1)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.1)
+ activemodel (= 3.1.1)
+ activesupport (= 3.1.1)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.1)
+ activemodel (= 3.1.1)
+ activesupport (= 3.1.1)
+ activesupport (3.1.1)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ builder (3.0.0)
+ coffee-rails (3.1.1)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.1.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.1.2)
+ erubis (2.7.0)
+ execjs (1.2.9)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.16)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.6.1)
+ mail (2.3.0)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ multi_json (1.0.3)
+ pdf-reader (0.10.1)
+ Ascii85 (~> 1.0.0)
+ polyglot (0.3.3)
+ prawn (0.12.0)
+ pdf-reader (>= 0.9.0)
+ ttfunk (~> 1.0.2)
+ rack (1.3.5)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.1.1)
+ actionmailer (= 3.1.1)
+ actionpack (= 3.1.1)
+ activerecord (= 3.1.1)
+ activeresource (= 3.1.1)
+ activesupport (= 3.1.1)
+ bundler (~> 1.0)
+ railties (= 3.1.1)
+ railties (3.1.1)
+ actionpack (= 3.1.1)
+ activesupport (= 3.1.1)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.11)
+ json (~> 1.4)
+ sass (3.1.10)
+ sass-rails (3.1.4)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (>= 3.1.4)
+ sprockets (~> 2.0.0)
+ tilt (~> 1.3.2)
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.4)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ ttfunk (1.0.3)
+ tzinfo (0.3.30)
+ uglifier (1.0.4)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ coffee-rails (~> 3.1.1)
+ jquery-rails
+ prawn
+ rails (= 3.1.1)
+ sass-rails (~> 3.1.4)
+ sqlite3
+ uglifier (>= 1.0.3)
@@ -0,0 +1,9 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:setup
+ rails s
+
+This example requires Ruby 1.9.2
@@ -0,0 +1,7 @@
+#!/usr/bin/env rake
+# 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__)
+
+Store::Application.load_tasks
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,9 @@
+// This is a manifest file that'll be compiled into including all the files listed below.
+// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
+// be included in the compiled file accessible from http://example.com/assets/application.js
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,92 @@
+/*
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
+ *= require_self
+ *= require_tree .
+*/
+
+body {
+ background-color: #4B7399;
+ font-family: Verdana, Helvetica, Arial;
+ font-size: 14px;
+}
+
+a img {
+ border: none;
+}
+
+a {
+ color: #0000FF;
+}
+
+.clear {
+ clear: both;
+ height: 0;
+ overflow: hidden;
+}
+
+#container {
+ width: 75%;
+ margin: 0 auto;
+ background-color: #FFF;
+ padding: 20px 40px;
+ border: solid 1px black;
+ margin-top: 20px;
+}
+
+#flash_notice, #flash_error, #flash_alert {
+ padding: 5px 8px;
+ margin: 10px 0;
+}
+
+#flash_notice {
+ background-color: #CFC;
+ border: solid 1px #6C6;
+}
+
+#flash_error, #flash_alert {
+ background-color: #FCC;
+ border: solid 1px #C66;
+}
+
+.fieldWithErrors {
+ display: inline;
+}
+
+.error_messages {
+ width: 400px;
+ border: 2px solid #CF0000;
+ padding: 0px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ font-size: 12px;
+}
+
+.error_messages h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 10px;
+ font-size: 12px;
+ margin: 0;
+ background-color: #c00;
+ color: #fff;
+}
+
+.error_messages p {
+ margin: 8px 10px;
+}
+
+.error_messages ul {
+ margin: 0;
+}
+
+form .field, form .actions {
+ margin: 12px 0;
+}
+
+.product h2 {
+ font-size: 16px;
+ margin-bottom: 2px;
+}
@@ -0,0 +1,37 @@
+#line_items {
+ border: solid 1px #666;
+ border-collapse: collapse;
+ margin: 10px 0;
+
+ th {
+ font-size: 10px;
+ color: #FFF;
+ background-color: #404C99;
+ padding: 4px 8px;
+ padding-bottom: 4px;
+ text-align: left;
+ }
+
+ td {
+ padding: 6px 12px;
+ }
+ .even td {
+ background-color: #E3E6FF;
+ }
+ .odd td {
+ background-color: #D1D8F6;
+ }
+
+ .price {
+ text-align: right;
+ font-weight: bold;
+ }
+
+ .qty {
+ text-align: center;
+ }
+
+ .total {
+ border-top: solid 1px #6D74C7;
+ }
+}
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,18 @@
+class OrdersController < ApplicationController
+ def index
+ @orders = Order.all
+ end
+
+ def show
+ @order = Order.find(params[:id])
+ respond_to do |format|
+ format.html
+ format.pdf do
+ pdf = OrderPdf.new(@order, view_context)
+ send_data pdf.render, filename: "order_#{@order.order_number}.pdf",
+ type: "application/pdf",
+ disposition: "inline"
+ end
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,2 @@
+module OrdersHelper
+end
@@ -0,0 +1,7 @@
+class LineItem < ActiveRecord::Base
+ belongs_to :order
+
+ def full_price
+ unit_price * quantity
+ end
+end
@@ -0,0 +1,8 @@
+class Order < ActiveRecord::Base
+ has_many :line_items
+
+ def total_price
+ # convert to array so it doesn't try to do sum on database directly
+ line_items.to_a.sum(&:full_price)
+ end
+end
Oops, something went wrong.

0 comments on commit 9fa0e0e

Please sign in to comment.