Permalink
Browse files

adding revised episode 17

  • Loading branch information...
1 parent 113bfa9 commit 24c7ae6248f909f6f3800b40b4e595d1545cae44 @ryanb committed Dec 23, 2011
Showing with 2,075 additions and 0 deletions.
  1. +12 −0 episode-017/README
  2. +5 −0 episode-017/store-after/.gitignore
  3. +15 −0 episode-017/store-after/Gemfile
  4. +114 −0 episode-017/store-after/Gemfile.lock
  5. +9 −0 episode-017/store-after/README
  6. +7 −0 episode-017/store-after/Rakefile
  7. BIN episode-017/store-after/app/assets/images/rails.png
  8. +9 −0 episode-017/store-after/app/assets/javascripts/application.js
  9. +11 −0 episode-017/store-after/app/assets/javascripts/products.js.coffee
  10. +137 −0 episode-017/store-after/app/assets/stylesheets/application.css.scss
  11. +3 −0 episode-017/store-after/app/assets/stylesheets/products.css.scss
  12. +3 −0 episode-017/store-after/app/controllers/application_controller.rb
  13. +41 −0 episode-017/store-after/app/controllers/products_controller.rb
  14. +2 −0 episode-017/store-after/app/helpers/application_helper.rb
  15. +2 −0 episode-017/store-after/app/helpers/products_helper.rb
  16. 0 episode-017/store-after/app/mailers/.gitkeep
  17. 0 episode-017/store-after/app/models/.gitkeep
  18. +4 −0 episode-017/store-after/app/models/categorization.rb
  19. +4 −0 episode-017/store-after/app/models/category.rb
  20. +4 −0 episode-017/store-after/app/models/product.rb
  21. +18 −0 episode-017/store-after/app/views/layouts/application.html.erb
  22. +32 −0 episode-017/store-after/app/views/products/_form.html.erb
  23. +6 −0 episode-017/store-after/app/views/products/edit.html.erb
  24. +14 −0 episode-017/store-after/app/views/products/index.html.erb
  25. +7 −0 episode-017/store-after/app/views/products/index.js.erb
  26. +5 −0 episode-017/store-after/app/views/products/new.html.erb
  27. +18 −0 episode-017/store-after/app/views/products/show.html.erb
  28. +4 −0 episode-017/store-after/config.ru
  29. +48 −0 episode-017/store-after/config/application.rb
  30. +6 −0 episode-017/store-after/config/boot.rb
  31. +25 −0 episode-017/store-after/config/database.yml
  32. +5 −0 episode-017/store-after/config/environment.rb
  33. +30 −0 episode-017/store-after/config/environments/development.rb
  34. +60 −0 episode-017/store-after/config/environments/production.rb
  35. +42 −0 episode-017/store-after/config/environments/test.rb
  36. +7 −0 episode-017/store-after/config/initializers/backtrace_silencers.rb
  37. +10 −0 episode-017/store-after/config/initializers/inflections.rb
  38. +5 −0 episode-017/store-after/config/initializers/mime_types.rb
  39. +7 −0 episode-017/store-after/config/initializers/secret_token.rb
  40. +8 −0 episode-017/store-after/config/initializers/session_store.rb
  41. +14 −0 episode-017/store-after/config/initializers/wrap_parameters.rb
  42. +5 −0 episode-017/store-after/config/locales/en.yml
  43. +4 −0 episode-017/store-after/config/routes.rb
  44. +10 −0 episode-017/store-after/db/migrate/20111005175852_create_products.rb
  45. +9 −0 episode-017/store-after/db/migrate/20111222193148_create_categories.rb
  46. +10 −0 episode-017/store-after/db/migrate/20111222235716_create_categorizations.rb
  47. +36 −0 episode-017/store-after/db/schema.rb
  48. +14 −0 episode-017/store-after/db/seeds.rb
  49. +2 −0 episode-017/store-after/doc/README_FOR_APP
  50. 0 episode-017/store-after/lib/assets/.gitkeep
  51. 0 episode-017/store-after/lib/tasks/.gitkeep
  52. 0 episode-017/store-after/log/.gitkeep
  53. +26 −0 episode-017/store-after/public/404.html
  54. +26 −0 episode-017/store-after/public/422.html
  55. +26 −0 episode-017/store-after/public/500.html
  56. 0 episode-017/store-after/public/favicon.ico
  57. +5 −0 episode-017/store-after/public/robots.txt
  58. +6 −0 episode-017/store-after/script/rails
  59. 0 episode-017/store-after/test/fixtures/.gitkeep
  60. +7 −0 episode-017/store-after/test/fixtures/categories.yml
  61. +9 −0 episode-017/store-after/test/fixtures/categorizations.yml
  62. 0 episode-017/store-after/test/functional/.gitkeep
  63. +49 −0 episode-017/store-after/test/functional/products_controller_test.rb
  64. 0 episode-017/store-after/test/integration/.gitkeep
  65. +12 −0 episode-017/store-after/test/performance/browsing_test.rb
  66. +13 −0 episode-017/store-after/test/test_helper.rb
  67. 0 episode-017/store-after/test/unit/.gitkeep
  68. +7 −0 episode-017/store-after/test/unit/categorization_test.rb
  69. +7 −0 episode-017/store-after/test/unit/category_test.rb
  70. +4 −0 episode-017/store-after/test/unit/helpers/products_helper_test.rb
  71. +7 −0 episode-017/store-after/test/unit/product_test.rb
  72. 0 episode-017/store-after/vendor/assets/stylesheets/.gitkeep
  73. 0 episode-017/store-after/vendor/plugins/.gitkeep
  74. +5 −0 episode-017/store-before/.gitignore
  75. +15 −0 episode-017/store-before/Gemfile
  76. +114 −0 episode-017/store-before/Gemfile.lock
  77. +9 −0 episode-017/store-before/README
  78. +7 −0 episode-017/store-before/Rakefile
  79. BIN episode-017/store-before/app/assets/images/rails.png
  80. +9 −0 episode-017/store-before/app/assets/javascripts/application.js
  81. +11 −0 episode-017/store-before/app/assets/javascripts/products.js.coffee
  82. +137 −0 episode-017/store-before/app/assets/stylesheets/application.css.scss
  83. +3 −0 episode-017/store-before/app/assets/stylesheets/products.css.scss
  84. +3 −0 episode-017/store-before/app/controllers/application_controller.rb
  85. +41 −0 episode-017/store-before/app/controllers/products_controller.rb
  86. +2 −0 episode-017/store-before/app/helpers/application_helper.rb
  87. +2 −0 episode-017/store-before/app/helpers/products_helper.rb
  88. 0 episode-017/store-before/app/mailers/.gitkeep
  89. 0 episode-017/store-before/app/models/.gitkeep
  90. +4 −0 episode-017/store-before/app/models/categorization.rb
  91. +4 −0 episode-017/store-before/app/models/category.rb
  92. +4 −0 episode-017/store-before/app/models/product.rb
  93. +18 −0 episode-017/store-before/app/views/layouts/application.html.erb
  94. +25 −0 episode-017/store-before/app/views/products/_form.html.erb
  95. +6 −0 episode-017/store-before/app/views/products/edit.html.erb
  96. +14 −0 episode-017/store-before/app/views/products/index.html.erb
  97. +7 −0 episode-017/store-before/app/views/products/index.js.erb
  98. +5 −0 episode-017/store-before/app/views/products/new.html.erb
  99. +18 −0 episode-017/store-before/app/views/products/show.html.erb
  100. +4 −0 episode-017/store-before/config.ru
  101. +48 −0 episode-017/store-before/config/application.rb
  102. +6 −0 episode-017/store-before/config/boot.rb
  103. +25 −0 episode-017/store-before/config/database.yml
  104. +5 −0 episode-017/store-before/config/environment.rb
  105. +30 −0 episode-017/store-before/config/environments/development.rb
  106. +60 −0 episode-017/store-before/config/environments/production.rb
  107. +42 −0 episode-017/store-before/config/environments/test.rb
  108. +7 −0 episode-017/store-before/config/initializers/backtrace_silencers.rb
  109. +10 −0 episode-017/store-before/config/initializers/inflections.rb
  110. +5 −0 episode-017/store-before/config/initializers/mime_types.rb
  111. +7 −0 episode-017/store-before/config/initializers/secret_token.rb
  112. +8 −0 episode-017/store-before/config/initializers/session_store.rb
  113. +14 −0 episode-017/store-before/config/initializers/wrap_parameters.rb
  114. +5 −0 episode-017/store-before/config/locales/en.yml
  115. +4 −0 episode-017/store-before/config/routes.rb
  116. +10 −0 episode-017/store-before/db/migrate/20111005175852_create_products.rb
  117. +9 −0 episode-017/store-before/db/migrate/20111222193148_create_categories.rb
  118. +10 −0 episode-017/store-before/db/migrate/20111222235716_create_categorizations.rb
  119. +36 −0 episode-017/store-before/db/schema.rb
  120. +14 −0 episode-017/store-before/db/seeds.rb
  121. +2 −0 episode-017/store-before/doc/README_FOR_APP
  122. 0 episode-017/store-before/lib/assets/.gitkeep
  123. 0 episode-017/store-before/lib/tasks/.gitkeep
  124. 0 episode-017/store-before/log/.gitkeep
  125. +26 −0 episode-017/store-before/public/404.html
  126. +26 −0 episode-017/store-before/public/422.html
  127. +26 −0 episode-017/store-before/public/500.html
  128. 0 episode-017/store-before/public/favicon.ico
  129. +5 −0 episode-017/store-before/public/robots.txt
  130. +6 −0 episode-017/store-before/script/rails
  131. 0 episode-017/store-before/test/fixtures/.gitkeep
  132. +7 −0 episode-017/store-before/test/fixtures/categories.yml
  133. +9 −0 episode-017/store-before/test/fixtures/categorizations.yml
  134. 0 episode-017/store-before/test/functional/.gitkeep
  135. +49 −0 episode-017/store-before/test/functional/products_controller_test.rb
  136. 0 episode-017/store-before/test/integration/.gitkeep
  137. +12 −0 episode-017/store-before/test/performance/browsing_test.rb
  138. +13 −0 episode-017/store-before/test/test_helper.rb
  139. 0 episode-017/store-before/test/unit/.gitkeep
  140. +7 −0 episode-017/store-before/test/unit/categorization_test.rb
  141. +7 −0 episode-017/store-before/test/unit/category_test.rb
  142. +4 −0 episode-017/store-before/test/unit/helpers/products_helper_test.rb
  143. +7 −0 episode-017/store-before/test/unit/product_test.rb
  144. 0 episode-017/store-before/vendor/assets/stylesheets/.gitkeep
  145. 0 episode-017/store-before/vendor/plugins/.gitkeep
View
@@ -0,0 +1,12 @@
+RailsCasts Episode #17: HABTM Checkboxes
+
+http://railscasts.com/episodes/17-habtm-checkboxes
+
+Commands used in console
+
+ p = Product.first
+ p.category_ids
+ p.category_ids = [1, 2]
+ p.categories
+
+Requires Ruby 1.9.2 or higher.
@@ -0,0 +1,5 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
+.sass-cache/
@@ -0,0 +1,15 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.1.3'
+
+gem 'sqlite3'
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', " ~> 3.1.0"
+ gem 'coffee-rails', "~> 3.1.0"
+ gem 'uglifier'
+end
+
+gem 'jquery-rails'
@@ -0,0 +1,114 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (3.1.3)
+ actionpack (= 3.1.3)
+ mail (~> 2.3.0)
+ actionpack (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ i18n (~> 0.6)
+ rack (~> 1.3.5)
+ rack-cache (~> 1.1)
+ rack-mount (~> 0.8.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.0.3)
+ activemodel (3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activeresource (3.1.3)
+ activemodel (= 3.1.3)
+ activesupport (= 3.1.3)
+ activesupport (3.1.3)
+ 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.3)
+ erubis (2.7.0)
+ execjs (1.2.12)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.19)
+ railties (~> 3.0)
+ thor (~> 0.14)
+ json (1.6.3)
+ 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.4)
+ polyglot (0.3.3)
+ 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.3)
+ actionmailer (= 3.1.3)
+ actionpack (= 3.1.3)
+ activerecord (= 3.1.3)
+ activeresource (= 3.1.3)
+ activesupport (= 3.1.3)
+ bundler (~> 1.0)
+ railties (= 3.1.3)
+ railties (3.1.3)
+ actionpack (= 3.1.3)
+ activesupport (= 3.1.3)
+ 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.11)
+ sass-rails (3.1.5)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (~> 3.1.10)
+ tilt (~> 1.3.2)
+ sprockets (2.0.3)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.5)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+ uglifier (1.2.0)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ coffee-rails (~> 3.1.0)
+ jquery-rails
+ rails (= 3.1.3)
+ sass-rails (~> 3.1.0)
+ sqlite3
+ uglifier
@@ -0,0 +1,9 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:setup
+ rails s
+
+Requires Ruby 1.9.2 or higher.
@@ -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,11 @@
+# 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/
+jQuery ->
+ if $('.pagination').length
+ $(window).scroll ->
+ url = $('.pagination .next_page').attr('href')
+ if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
+ $('.pagination').text("Fetching more products...")
+ $.getScript(url)
+ $(window).scroll()
@@ -0,0 +1,137 @@
+/*
+ * 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;
+}
+
+.pagination {
+ background: white;
+ cursor: default;
+ margin-top: 20px;
+ a, span, em {
+ padding: 0.2em 0.5em;
+ display: block;
+ float: left;
+ margin-right: 1px;
+ }
+ .disabled {
+ color: #777;
+ border: solid 1px #CCC;
+ }
+ .current {
+ font-style: normal;
+ font-weight: bold;
+ background: #2e6ab1;
+ color: white;
+ border: 1px solid #2e6ab1;
+ }
+ a {
+ text-decoration: none;
+ color: #105cb6;
+ border: 1px solid #9aafe5;
+ &:hover, &:focus {
+ color: #000033;
+ border-color: #000033;
+ }
+ }
+ .page_info {
+ background: #2e6ab1;
+ color: white;
+ padding: 0.4em 0.6em;
+ width: 22em;
+ margin-bottom: 0.3em;
+ text-align: center;
+ b {
+ color: #000033;
+ background: #2e6ab1 + 60;
+ padding: 0.1em 0.25em;
+ }
+ }
+}
@@ -0,0 +1,3 @@
+// Place all the styles related to the products controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,41 @@
+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
+ redirect_to @product, notice: "Successfully created product."
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @product = Product.find(params[:id])
+ end
+
+ def update
+ @product = Product.find(params[:id])
+ if @product.update_attributes(params[:product])
+ redirect_to @product, notice: "Successfully created product."
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @product = Product.find(params[:id])
+ @product.destroy
+ redirect_to products_url, notice: "Successfully destroyed product."
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,2 @@
+module ProductsHelper
+end
@@ -0,0 +1,4 @@
+class Categorization < ActiveRecord::Base
+ belongs_to :category
+ belongs_to :product
+end
@@ -0,0 +1,4 @@
+class Category < ActiveRecord::Base
+ has_many :categorizations
+ has_many :products, through: :categorizations
+end
@@ -0,0 +1,4 @@
+class Product < ActiveRecord::Base
+ has_many :categorizations
+ has_many :categories, through: :categorizations
+end
Oops, something went wrong.

0 comments on commit 24c7ae6

Please sign in to comment.