Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding revised episode 234

  • Loading branch information...
commit f2cded49f3d3eccf29c5c3c0145d7aad960a6657 1 parent c0330a8
Ryan Bates authored
Showing with 2,531 additions and 0 deletions.
  1. +11 −0 episode-234/revised/README.md
  2. +15 −0 episode-234/revised/store-after/.gitignore
  3. +40 −0 episode-234/revised/store-after/Gemfile
  4. +115 −0 episode-234/revised/store-after/Gemfile.lock
  5. +7 −0 episode-234/revised/store-after/README.rdoc
  6. +7 −0 episode-234/revised/store-after/Rakefile
  7. BIN  episode-234/revised/store-after/app/assets/images/rails.png
  8. +15 −0 episode-234/revised/store-after/app/assets/javascripts/application.js
  9. +3 −0  episode-234/revised/store-after/app/assets/javascripts/products.js.coffee
  10. +92 −0 episode-234/revised/store-after/app/assets/stylesheets/application.css
  11. +47 −0 episode-234/revised/store-after/app/assets/stylesheets/forms.css.scss
  12. +3 −0  episode-234/revised/store-after/app/assets/stylesheets/products.css.scss
  13. +3 −0  episode-234/revised/store-after/app/controllers/application_controller.rb
  14. +41 −0 episode-234/revised/store-after/app/controllers/products_controller.rb
  15. +2 −0  episode-234/revised/store-after/app/helpers/application_helper.rb
  16. +2 −0  episode-234/revised/store-after/app/helpers/products_helper.rb
  17. 0  episode-234/revised/store-after/app/mailers/.gitkeep
  18. 0  episode-234/revised/store-after/app/models/.gitkeep
  19. +4 −0 episode-234/revised/store-after/app/models/categorization.rb
  20. +4 −0 episode-234/revised/store-after/app/models/category.rb
  21. +7 −0 episode-234/revised/store-after/app/models/product.rb
  22. +3 −0  episode-234/revised/store-after/app/models/publisher.rb
  23. +17 −0 episode-234/revised/store-after/app/views/layouts/application.html.erb
  24. +12 −0 episode-234/revised/store-after/app/views/products/_form.html.erb
  25. +3 −0  episode-234/revised/store-after/app/views/products/edit.html.erb
  26. +14 −0 episode-234/revised/store-after/app/views/products/index.html.erb
  27. +3 −0  episode-234/revised/store-after/app/views/products/new.html.erb
  28. +35 −0 episode-234/revised/store-after/app/views/products/show.html.erb
  29. +4 −0 episode-234/revised/store-after/config.ru
  30. +59 −0 episode-234/revised/store-after/config/application.rb
  31. +6 −0 episode-234/revised/store-after/config/boot.rb
  32. +25 −0 episode-234/revised/store-after/config/database.yml
  33. +5 −0 episode-234/revised/store-after/config/environment.rb
  34. +37 −0 episode-234/revised/store-after/config/environments/development.rb
  35. +67 −0 episode-234/revised/store-after/config/environments/production.rb
  36. +37 −0 episode-234/revised/store-after/config/environments/test.rb
  37. +7 −0 episode-234/revised/store-after/config/initializers/backtrace_silencers.rb
  38. +15 −0 episode-234/revised/store-after/config/initializers/inflections.rb
  39. +5 −0 episode-234/revised/store-after/config/initializers/mime_types.rb
  40. +7 −0 episode-234/revised/store-after/config/initializers/secret_token.rb
  41. +8 −0 episode-234/revised/store-after/config/initializers/session_store.rb
  42. +136 −0 episode-234/revised/store-after/config/initializers/simple_form.rb
  43. +14 −0 episode-234/revised/store-after/config/initializers/wrap_parameters.rb
  44. +5 −0 episode-234/revised/store-after/config/locales/en.yml
  45. +24 −0 episode-234/revised/store-after/config/locales/simple_form.en.yml
  46. +4 −0 episode-234/revised/store-after/config/routes.rb
  47. +14 −0 episode-234/revised/store-after/db/migrate/20120302190644_create_products.rb
  48. +9 −0 episode-234/revised/store-after/db/migrate/20120302190906_create_categories.rb
  49. +10 −0 episode-234/revised/store-after/db/migrate/20120302191003_create_categorizations.rb
  50. +9 −0 episode-234/revised/store-after/db/migrate/20120302191013_create_publishers.rb
  51. +46 −0 episode-234/revised/store-after/db/schema.rb
  52. +58 −0 episode-234/revised/store-after/db/seeds.rb
  53. +2 −0  episode-234/revised/store-after/doc/README_FOR_APP
  54. 0  episode-234/revised/store-after/lib/assets/.gitkeep
  55. 0  episode-234/revised/store-after/lib/tasks/.gitkeep
  56. +13 −0 episode-234/revised/store-after/lib/templates/erb/scaffold/_form.html.erb
  57. 0  episode-234/revised/store-after/log/.gitkeep
  58. +26 −0 episode-234/revised/store-after/public/404.html
  59. +26 −0 episode-234/revised/store-after/public/422.html
  60. +25 −0 episode-234/revised/store-after/public/500.html
  61. 0  episode-234/revised/store-after/public/favicon.ico
  62. +5 −0 episode-234/revised/store-after/public/robots.txt
  63. +6 −0 episode-234/revised/store-after/script/rails
  64. 0  episode-234/revised/store-after/test/fixtures/.gitkeep
  65. +7 −0 episode-234/revised/store-after/test/fixtures/categories.yml
  66. +9 −0 episode-234/revised/store-after/test/fixtures/categorizations.yml
  67. +17 −0 episode-234/revised/store-after/test/fixtures/products.yml
  68. +7 −0 episode-234/revised/store-after/test/fixtures/publishers.yml
  69. 0  episode-234/revised/store-after/test/functional/.gitkeep
  70. +49 −0 episode-234/revised/store-after/test/functional/products_controller_test.rb
  71. 0  episode-234/revised/store-after/test/integration/.gitkeep
  72. +12 −0 episode-234/revised/store-after/test/performance/browsing_test.rb
  73. +13 −0 episode-234/revised/store-after/test/test_helper.rb
  74. 0  episode-234/revised/store-after/test/unit/.gitkeep
  75. +7 −0 episode-234/revised/store-after/test/unit/categorization_test.rb
  76. +7 −0 episode-234/revised/store-after/test/unit/category_test.rb
  77. +4 −0 episode-234/revised/store-after/test/unit/helpers/products_helper_test.rb
  78. +7 −0 episode-234/revised/store-after/test/unit/product_test.rb
  79. +7 −0 episode-234/revised/store-after/test/unit/publisher_test.rb
  80. 0  episode-234/revised/store-after/vendor/assets/javascripts/.gitkeep
  81. 0  episode-234/revised/store-after/vendor/assets/stylesheets/.gitkeep
  82. 0  episode-234/revised/store-after/vendor/plugins/.gitkeep
  83. +15 −0 episode-234/revised/store-before/.gitignore
  84. +38 −0 episode-234/revised/store-before/Gemfile
  85. +111 −0 episode-234/revised/store-before/Gemfile.lock
  86. +7 −0 episode-234/revised/store-before/README.rdoc
  87. +7 −0 episode-234/revised/store-before/Rakefile
  88. BIN  episode-234/revised/store-before/app/assets/images/rails.png
  89. +15 −0 episode-234/revised/store-before/app/assets/javascripts/application.js
  90. +3 −0  episode-234/revised/store-before/app/assets/javascripts/products.js.coffee
  91. +92 −0 episode-234/revised/store-before/app/assets/stylesheets/application.css
  92. +3 −0  episode-234/revised/store-before/app/assets/stylesheets/products.css.scss
  93. +3 −0  episode-234/revised/store-before/app/controllers/application_controller.rb
  94. +41 −0 episode-234/revised/store-before/app/controllers/products_controller.rb
  95. +2 −0  episode-234/revised/store-before/app/helpers/application_helper.rb
  96. +2 −0  episode-234/revised/store-before/app/helpers/products_helper.rb
  97. 0  episode-234/revised/store-before/app/mailers/.gitkeep
  98. 0  episode-234/revised/store-before/app/models/.gitkeep
  99. +4 −0 episode-234/revised/store-before/app/models/categorization.rb
  100. +4 −0 episode-234/revised/store-before/app/models/category.rb
  101. +5 −0 episode-234/revised/store-before/app/models/product.rb
  102. +3 −0  episode-234/revised/store-before/app/models/publisher.rb
  103. +17 −0 episode-234/revised/store-before/app/views/layouts/application.html.erb
  104. +52 −0 episode-234/revised/store-before/app/views/products/_form.html.erb
  105. +3 −0  episode-234/revised/store-before/app/views/products/edit.html.erb
  106. +14 −0 episode-234/revised/store-before/app/views/products/index.html.erb
  107. +3 −0  episode-234/revised/store-before/app/views/products/new.html.erb
  108. +35 −0 episode-234/revised/store-before/app/views/products/show.html.erb
  109. +4 −0 episode-234/revised/store-before/config.ru
  110. +59 −0 episode-234/revised/store-before/config/application.rb
  111. +6 −0 episode-234/revised/store-before/config/boot.rb
  112. +25 −0 episode-234/revised/store-before/config/database.yml
  113. +5 −0 episode-234/revised/store-before/config/environment.rb
  114. +37 −0 episode-234/revised/store-before/config/environments/development.rb
  115. +67 −0 episode-234/revised/store-before/config/environments/production.rb
  116. +37 −0 episode-234/revised/store-before/config/environments/test.rb
  117. +7 −0 episode-234/revised/store-before/config/initializers/backtrace_silencers.rb
  118. +15 −0 episode-234/revised/store-before/config/initializers/inflections.rb
  119. +5 −0 episode-234/revised/store-before/config/initializers/mime_types.rb
  120. +7 −0 episode-234/revised/store-before/config/initializers/secret_token.rb
  121. +8 −0 episode-234/revised/store-before/config/initializers/session_store.rb
  122. +14 −0 episode-234/revised/store-before/config/initializers/wrap_parameters.rb
  123. +5 −0 episode-234/revised/store-before/config/locales/en.yml
  124. +4 −0 episode-234/revised/store-before/config/routes.rb
  125. +14 −0 episode-234/revised/store-before/db/migrate/20120302190644_create_products.rb
  126. +9 −0 episode-234/revised/store-before/db/migrate/20120302190906_create_categories.rb
  127. +10 −0 episode-234/revised/store-before/db/migrate/20120302191003_create_categorizations.rb
  128. +9 −0 episode-234/revised/store-before/db/migrate/20120302191013_create_publishers.rb
  129. +46 −0 episode-234/revised/store-before/db/schema.rb
  130. +58 −0 episode-234/revised/store-before/db/seeds.rb
  131. +2 −0  episode-234/revised/store-before/doc/README_FOR_APP
  132. 0  episode-234/revised/store-before/lib/assets/.gitkeep
  133. 0  episode-234/revised/store-before/lib/tasks/.gitkeep
  134. 0  episode-234/revised/store-before/log/.gitkeep
  135. +26 −0 episode-234/revised/store-before/public/404.html
  136. +26 −0 episode-234/revised/store-before/public/422.html
  137. +25 −0 episode-234/revised/store-before/public/500.html
  138. 0  episode-234/revised/store-before/public/favicon.ico
  139. +5 −0 episode-234/revised/store-before/public/robots.txt
  140. +6 −0 episode-234/revised/store-before/script/rails
  141. 0  episode-234/revised/store-before/test/fixtures/.gitkeep
  142. +7 −0 episode-234/revised/store-before/test/fixtures/categories.yml
  143. +9 −0 episode-234/revised/store-before/test/fixtures/categorizations.yml
  144. +17 −0 episode-234/revised/store-before/test/fixtures/products.yml
  145. +7 −0 episode-234/revised/store-before/test/fixtures/publishers.yml
  146. 0  episode-234/revised/store-before/test/functional/.gitkeep
  147. +49 −0 episode-234/revised/store-before/test/functional/products_controller_test.rb
  148. 0  episode-234/revised/store-before/test/integration/.gitkeep
  149. +12 −0 episode-234/revised/store-before/test/performance/browsing_test.rb
  150. +13 −0 episode-234/revised/store-before/test/test_helper.rb
  151. 0  episode-234/revised/store-before/test/unit/.gitkeep
  152. +7 −0 episode-234/revised/store-before/test/unit/categorization_test.rb
  153. +7 −0 episode-234/revised/store-before/test/unit/category_test.rb
  154. +4 −0 episode-234/revised/store-before/test/unit/helpers/products_helper_test.rb
  155. +7 −0 episode-234/revised/store-before/test/unit/product_test.rb
  156. +7 −0 episode-234/revised/store-before/test/unit/publisher_test.rb
  157. 0  episode-234/revised/store-before/vendor/assets/javascripts/.gitkeep
  158. 0  episode-234/revised/store-before/vendor/assets/stylesheets/.gitkeep
  159. 0  episode-234/revised/store-before/vendor/plugins/.gitkeep
11 episode-234/revised/README.md
View
@@ -0,0 +1,11 @@
+# RailsCasts Episode #234: SimpleForm (revised)
+
+http://railscasts.com/episodes/234-simple-form-revised
+
+Requires Ruby 1.9.2 or higher.
+
+Commands used in episode:
+
+```
+rails g simple_form:install
+```
15 episode-234/revised/store-after/.gitignore
View
@@ -0,0 +1,15 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
40 episode-234/revised/store-after/Gemfile
View
@@ -0,0 +1,40 @@
+source 'https://rubygems.org'
+
+gem 'rails', '3.2.2'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3'
+
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', '~> 3.2.3'
+ gem 'coffee-rails', '~> 3.2.1'
+
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
+ # gem 'therubyracer'
+
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+
+# To use ActiveModel has_secure_password
+# gem 'bcrypt-ruby', '~> 3.0.0'
+
+# To use Jbuilder templates for JSON
+# gem 'jbuilder'
+
+# Use unicorn as the app server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+gem 'simple_form'
115 episode-234/revised/store-after/Gemfile.lock
View
@@ -0,0 +1,115 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (3.2.2)
+ actionpack (= 3.2.2)
+ mail (~> 2.4.0)
+ actionpack (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.1)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ activerecord (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ activesupport (3.2.2)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.0)
+ coffee-rails (3.2.2)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.2.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.2.0)
+ erubis (2.7.0)
+ execjs (1.3.0)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.3)
+ jquery-rails (2.0.1)
+ railties (>= 3.2.0, < 5.0)
+ thor (~> 0.14)
+ json (1.6.5)
+ mail (2.4.1)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ multi_json (1.1.0)
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.2)
+ actionmailer (= 3.2.2)
+ actionpack (= 3.2.2)
+ activerecord (= 3.2.2)
+ activeresource (= 3.2.2)
+ activesupport (= 3.2.2)
+ bundler (~> 1.0)
+ railties (= 3.2.2)
+ railties (3.2.2)
+ actionpack (= 3.2.2)
+ activesupport (= 3.2.2)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ sass (3.1.15)
+ sass-rails (3.2.4)
+ railties (~> 3.2.0)
+ sass (>= 3.1.10)
+ tilt (~> 1.3)
+ simple_form (2.0.1)
+ actionpack (~> 3.0)
+ activemodel (~> 3.0)
+ sprockets (2.1.2)
+ 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.3)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ coffee-rails (~> 3.2.1)
+ jquery-rails
+ rails (= 3.2.2)
+ sass-rails (~> 3.2.3)
+ simple_form
+ sqlite3
+ uglifier (>= 1.0.3)
7 episode-234/revised/store-after/README.rdoc
View
@@ -0,0 +1,7 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:setup
+ rails s
7 episode-234/revised/store-after/Rakefile
View
@@ -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
BIN  episode-234/revised/store-after/app/assets/images/rails.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 episode-234/revised/store-after/app/assets/javascripts/application.js
View
@@ -0,0 +1,15 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
+// GO AFTER THE REQUIRES BELOW.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
3  episode-234/revised/store-after/app/assets/javascripts/products.js.coffee
View
@@ -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/
92 episode-234/revised/store-after/app/assets/stylesheets/application.css
View
@@ -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;
+}
47 episode-234/revised/store-after/app/assets/stylesheets/forms.css.scss
View
@@ -0,0 +1,47 @@
+.simple_form {
+ $indent: 120px;
+ label {
+ float: left;
+ width: $indent - 20px;
+ text-align: right;
+ margin: 2px 10px;
+ &.radio, &.checkbox {
+ float: none;
+ margin: 0;
+ width: auto;
+ text-align: left;
+ }
+ &.checkbox {
+ display: block;
+ margin-left: $indent;
+ }
+ &.radio {
+ margin-right: 10px;
+ }
+ }
+ div.input {
+ margin-bottom: 10px;
+ }
+ input.radio_buttons, input.check_boxes {
+ margin-right: 5px;
+ }
+ .btn {
+ margin-left: $indent;
+ }
+ .alert-error {
+ color: #D00;
+ margin-bottom: 10px;
+ font-weight: bold;
+ }
+ .hint, .error {
+ clear: left;
+ margin-left: $indent;
+ font-size: 12px;
+ color: #D00;
+ display: block;
+ }
+ .hint {
+ color: #555;
+ font-style: italic;
+ }
+}
3  episode-234/revised/store-after/app/assets/stylesheets/products.css.scss
View
@@ -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/
3  episode-234/revised/store-after/app/controllers/application_controller.rb
View
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
41 episode-234/revised/store-after/app/controllers/products_controller.rb
View
@@ -0,0 +1,41 @@
+class ProductsController < ApplicationController
+ def index
+ @products = Product.order("name")
+ 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
2  episode-234/revised/store-after/app/helpers/application_helper.rb
View
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
2  episode-234/revised/store-after/app/helpers/products_helper.rb
View
@@ -0,0 +1,2 @@
+module ProductsHelper
+end
0  episode-234/revised/store-after/app/mailers/.gitkeep
View
No changes.
0  episode-234/revised/store-after/app/models/.gitkeep
View
No changes.
4 episode-234/revised/store-after/app/models/categorization.rb
View
@@ -0,0 +1,4 @@
+class Categorization < ActiveRecord::Base
+ belongs_to :product
+ belongs_to :category
+end
4 episode-234/revised/store-after/app/models/category.rb
View
@@ -0,0 +1,4 @@
+class Category < ActiveRecord::Base
+ has_many :categorizations
+ has_many :products, through: :categorizations
+end
7 episode-234/revised/store-after/app/models/product.rb
View
@@ -0,0 +1,7 @@
+class Product < ActiveRecord::Base
+ belongs_to :publisher
+ has_many :categorizations
+ has_many :categories, through: :categorizations
+
+ validates_presence_of :name
+end
3  episode-234/revised/store-after/app/models/publisher.rb
View
@@ -0,0 +1,3 @@
+class Publisher < ActiveRecord::Base
+ has_many :products
+end
17 episode-234/revised/store-after/app/views/layouts/application.html.erb
View
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Store</title>
+ <%= stylesheet_link_tag "application", media: "all" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, id: "flash_#{name}" %>
+ <% end %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
12 episode-234/revised/store-after/app/views/products/_form.html.erb
View
@@ -0,0 +1,12 @@
+<%= simple_form_for(@product) do |f| %>
+ <%= f.error_notification %>
+ <%= f.input :name %>
+ <%= f.input :price, hint: "price should be in USD" %>
+ <%= f.input :released_on, label: "Release Date" %>
+ <%= f.input :discontinued %>
+ <%= f.input :rating, collection: 1..5, as: :radio_buttons %>
+ <%= f.association :publisher %>
+ <%= f.association :categories, as: :check_boxes %>
+ <%= f.error :base %>
+ <%= f.button :submit %>
+<% end %>
3  episode-234/revised/store-after/app/views/products/edit.html.erb
View
@@ -0,0 +1,3 @@
+<h1>Editing Product</h1>
+
+<%= render 'form' %>
14 episode-234/revised/store-after/app/views/products/index.html.erb
View
@@ -0,0 +1,14 @@
+<h1>Games</h1>
+
+<% @products.each do |product| %>
+ <div class="product">
+ <h2><%= link_to product.name, product %></h2>
+ <div class="details">
+ <%= number_to_currency(product.price) %> |
+ <%= product.categories.map(&:name).join(", ") %> |
+ <%= product.publisher.name %>
+ </div>
+ </div>
+<% end %>
+
+<p><%= link_to "New Product", new_product_path %></p>
3  episode-234/revised/store-after/app/views/products/new.html.erb
View
@@ -0,0 +1,3 @@
+<h1>New Product</h1>
+
+<%= render 'form' %>
35 episode-234/revised/store-after/app/views/products/show.html.erb
View
@@ -0,0 +1,35 @@
+<h1><%= @product.name %></h1>
+
+<p>
+ <b>Price:</b>
+ <%= number_to_currency(@product.price) %>
+</p>
+
+<p>
+ <b>Categories:</b>
+ <%= @product.categories.map(&:name).join(", ") %>
+</p>
+
+<p>
+ <b>Released on:</b>
+ <%= @product.released_on.strftime("%B %e, %Y") %>
+</p>
+
+<p>
+ <b>Publisher:</b>
+ <%= @product.publisher.try(:name) %>
+</p>
+
+<p>
+ <b>Rating:</b>
+ <%= @product.rating %>
+</p>
+
+<p>
+ <b>Discontinued:</b>
+ <%= @product.discontinued ? "Yes" : "No" %>
+</p>
+
+
+<%= link_to 'Edit', edit_product_path(@product) %> |
+<%= link_to 'Back', products_path %>
4 episode-234/revised/store-after/config.ru
View
@@ -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
59 episode-234/revised/store-after/config/application.rb
View
@@ -0,0 +1,59 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+if defined?(Bundler)
+ # If you precompile assets before deploying to production, use this line
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
+ # If you want your assets lazily compiled in production, use this line
+ # Bundler.require(:default, :assets, Rails.env)
+end
+
+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.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_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 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]
+
+ # Use SQL instead of Active Record's schema dumper when creating the database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Enforce whitelist mode for mass assignment.
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
+ # parameters by using an attr_accessible or attr_protected declaration.
+ # config.active_record.whitelist_attributes = true
+
+ # Enable the asset pipeline
+ config.assets.enabled = true
+
+ # Version of your assets, change this if you want to expire all your assets
+ config.assets.version = '1.0'
+ end
+end
6 episode-234/revised/store-after/config/boot.rb
View
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
25 episode-234/revised/store-after/config/database.yml
View
@@ -0,0 +1,25 @@
+# SQLite version 3.x
+# gem install sqlite3
+#
+# Ensure the SQLite 3 gem is defined in your Gemfile
+# gem 'sqlite3'
+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
5 episode-234/revised/store-after/config/environment.rb
View
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Store::Application.initialize!
37 episode-234/revised/store-after/config/environments/development.rb
View
@@ -0,0 +1,37 @@
+Store::Application.configure do
+ # Settings specified here will take precedence over those in config/application.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 web server 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_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+
+ # Raise exception on mass assignment protection for Active Record models
+ config.active_record.mass_assignment_sanitizer = :strict
+
+ # Log the query plan for queries taking more than this (works
+ # with SQLite, MySQL, and PostgreSQL)
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
+
+ # Do not compress assets
+ config.assets.compress = false
+
+ # Expands the lines which load the assets
+ config.assets.debug = true
+end
67 episode-234/revised/store-after/config/environments/production.rb
View
@@ -0,0 +1,67 @@
+Store::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # Code is not reloaded between requests
+ config.cache_classes = true
+
+ # Full error reports are disabled and caching is turned on
+ config.consider_all_requests_local = false
+ config.action_controller.perform_caching = true
+
+ # Disable Rails's static asset server (Apache or nginx will already do this)
+ config.serve_static_assets = false
+
+ # Compress JavaScripts and CSS
+ config.assets.compress = true
+
+ # Don't fallback to assets pipeline if a precompiled asset is missed
+ config.assets.compile = false
+
+ # Generate digests for assets URLs
+ config.assets.digest = true
+
+ # Defaults to Rails.root.join("public/assets")
+ # config.assets.manifest = YOUR_PATH
+
+ # Specifies the header that your server uses for sending files
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
+
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
+
+ # See everything in the log (default is :info)
+ # config.log_level = :debug
+
+ # Prepend all log lines with the following tags
+ # config.log_tags = [ :subdomain, :uuid ]
+
+ # Use a different logger for distributed setups
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
+
+ # Use a different cache store in production
+ # config.cache_store = :mem_cache_store
+
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
+ # config.action_controller.asset_host = "http://assets.example.com"
+
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
+ # config.assets.precompile += %w( search.js )
+
+ # Disable delivery errors, bad email addresses will be ignored
+ # config.action_mailer.raise_delivery_errors = false
+
+ # Enable threaded mode
+ # config.threadsafe!
+
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
+ # the I18n.default_locale when a translation can not be found)
+ config.i18n.fallbacks = true
+
+ # Send deprecation notices to registered listeners
+ config.active_support.deprecation = :notify
+
+ # Log the query plan for queries taking more than this (works
+ # with SQLite, MySQL, and PostgreSQL)
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
+end
37 episode-234/revised/store-after/config/environments/test.rb
View
@@ -0,0 +1,37 @@
+Store::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # The test environment is used exclusively to run your application's
+ # test suite. You never need to work with it otherwise. Remember that
+ # your test database is "scratch space" for the test suite and is wiped
+ # and recreated between test runs. Don't rely on the data there!
+ config.cache_classes = true
+
+ # Configure static asset server for tests with Cache-Control for performance
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=3600"
+
+ # 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_controller.perform_caching = false
+
+ # Raise exceptions instead of rendering exception templates
+ config.action_dispatch.show_exceptions = false
+
+ # Disable request forgery protection in test environment
+ config.action_controller.allow_forgery_protection = false
+
+ # Tell Action Mailer not to deliver emails to the real world.
+ # The :test delivery method accumulates sent emails in the
+ # ActionMailer::Base.deliveries array.
+ config.action_mailer.delivery_method = :test
+
+ # Raise exception on mass assignment protection for Active Record models
+ config.active_record.mass_assignment_sanitizer = :strict
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
7 episode-234/revised/store-after/config/initializers/backtrace_silencers.rb
View
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
+
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
+# Rails.backtrace_cleaner.remove_silencers!
15 episode-234/revised/store-after/config/initializers/inflections.rb
View
@@ -0,0 +1,15 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new inflection rules using the following format
+# (all these examples are active by default):
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.plural /^(ox)$/i, '\1en'
+# inflect.singular /^(ox)en/i, '\1'
+# inflect.irregular 'person', 'people'
+# inflect.uncountable %w( fish sheep )
+# end
+#
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.acronym 'RESTful'
+# end
5 episode-234/revised/store-after/config/initializers/mime_types.rb
View
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Add new mime types for use in respond_to blocks:
+# Mime::Type.register "text/richtext", :rtf
+# Mime::Type.register_alias "text/html", :iphone
7 episode-234/revised/store-after/config/initializers/secret_token.rb
View
@@ -0,0 +1,7 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying the integrity of signed cookies.
+# If you change this key, all old signed cookies will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+Store::Application.config.secret_token = '4122882dd0dec749308315eba2b6a98cc0b1839e6ce291c94569a7fcf37acc5730ae26b37d5deb410f827986ed851dfa54887337fb3eecc8031db7b917ba7a0e'
8 episode-234/revised/store-after/config/initializers/session_store.rb
View
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Store::Application.config.session_store :cookie_store, key: '_store_session'
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rails generate session_migration")
+# Store::Application.config.session_store :active_record_store
136 episode-234/revised/store-after/config/initializers/simple_form.rb
View
@@ -0,0 +1,136 @@
+# Use this setup block to configure all options available in SimpleForm.
+SimpleForm.setup do |config|
+ # Wrappers are used by the form builder to generate a
+ # complete input. You can remove any component from the
+ # wrapper, change the order or even add your own to the
+ # stack. The options given below are used to wrap the
+ # whole input.
+ config.wrappers :default, :class => :input,
+ :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
+ ## Extensions enabled by default
+ # Any of these extensions can be disabled for a
+ # given input by passing: `f.input EXTENSION_NAME => false`.
+ # You can make any of these extensions optional by
+ # renaming `b.use` to `b.optional`.
+
+ # Determines whether to use HTML5 (:email, :url, ...)
+ # and required attributes
+ b.use :html5
+
+ # Calculates placeholders automatically from I18n
+ # You can also pass a string as f.input :placeholder => "Placeholder"
+ b.use :placeholder
+
+ ## Optional extensions
+ # They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
+ # to the input. If so, they will retrieve the values from the model
+ # if any exists. If you want to enable the lookup for any of those
+ # extensions by default, you can change `b.optional` to `b.use`.
+
+ # Calculates maxlength from length validations for string inputs
+ b.optional :maxlength
+
+ # Calculates pattern from format validations for string inputs
+ b.optional :pattern
+
+ # Calculates min and max from length validations for numeric inputs
+ b.optional :min_max
+
+ # Calculates readonly automatically from readonly attributes
+ b.optional :readonly
+
+ ## Inputs
+ b.use :label_input
+ b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
+ b.use :error, :wrap_with => { :tag => :span, :class => :error }
+ end
+
+ # The default wrapper to be used by the FormBuilder.
+ config.default_wrapper = :default
+
+ # Define the way to render check boxes / radio buttons with labels.
+ # Defaults to :nested for bootstrap config.
+ # :inline => input + label
+ # :nested => label > input
+ config.boolean_style = :nested
+
+ # Default class for buttons
+ config.button_class = 'btn'
+
+ # Method used to tidy up errors.
+ # config.error_method = :first
+
+ # Default tag used for error notification helper.
+ config.error_notification_tag = :div
+
+ # CSS class to add for error notification helper.
+ config.error_notification_class = 'alert alert-error'
+
+ # ID to add for error notification helper.
+ # config.error_notification_id = nil
+
+ # Series of attempts to detect a default label method for collection.
+ # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
+
+ # Series of attempts to detect a default value method for collection.
+ # config.collection_value_methods = [ :id, :to_s ]
+
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
+ # config.collection_wrapper_tag = nil
+
+ # You can define the class to use on all collection wrappers. Defaulting to none.
+ # config.collection_wrapper_class = nil
+
+ # You can wrap each item in a collection of radio/check boxes with a tag,
+ # defaulting to :span. Please note that when using :boolean_style = :nested,
+ # SimpleForm will force this option to be a label.
+ # config.item_wrapper_tag = :span
+
+ # You can define a class to use in all item wrappers. Defaulting to none.
+ # config.item_wrapper_class = nil
+
+ # How the label text should be generated altogether with the required text.
+ # config.label_text = lambda { |label, required| "#{required} #{label}" }
+
+ # You can define the class to use on all labels. Default is nil.
+ config.label_class = 'control-label'
+
+ # You can define the class to use on all forms. Default is simple_form.
+ # config.form_class = :simple_form
+
+ # You can define which elements should obtain additional classes
+ # config.generate_additional_classes_for = [:wrapper, :label, :input]
+
+ # Whether attributes are required by default (or not). Default is true.
+ # config.required_by_default = true
+
+ # Tell browsers whether to use default HTML5 validations (novalidate option).
+ # Default is enabled.
+ config.browser_validations = false
+
+ # Collection of methods to detect if a file type was given.
+ # config.file_methods = [ :mounted_as, :file?, :public_filename ]
+
+ # Custom mappings for input types. This should be a hash containing a regexp
+ # to match as key, and the input type that will be used when the field name
+ # matches the regexp as value.
+ # config.input_mappings = { /count/ => :integer }
+
+ # Default priority for time_zone inputs.
+ # config.time_zone_priority = nil
+
+ # Default priority for country inputs.
+ # config.country_priority = nil
+
+ # Default size for text inputs.
+ config.default_input_size = 30
+
+ # When false, do not use translations for labels.
+ # config.translate_labels = true
+
+ # Automatically discover new inputs in Rails' autoload path.
+ # config.inputs_discovery = true
+
+ # Cache SimpleForm inputs discovery
+ # config.cache_discovery = !Rails.env.development?
+end
14 episode-234/revised/store-after/config/initializers/wrap_parameters.rb
View
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+#
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# Disable root element in JSON by default.
+ActiveSupport.on_load(:active_record) do
+ self.include_root_in_json = false
+end
5 episode-234/revised/store-after/config/locales/en.yml
View
@@ -0,0 +1,5 @@
+# Sample localization file for English. Add more files in this directory for other locales.
+# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
+
+en:
+ hello: "Hello world"
24 episode-234/revised/store-after/config/locales/simple_form.en.yml
View
@@ -0,0 +1,24 @@
+en:
+ simple_form:
+ "yes": 'Yes'
+ "no": 'No'
+ required:
+ text: 'required'
+ mark: '**'
+ # You can uncomment the line below if you need to overwrite the whole required html.
+ # When using html, text and mark won't be used.
+ # html: '<abbr title="required">*</abbr>'
+ error_notification:
+ default_message: "Some errors were found, please take a look:"
+ # Labels and hints examples
+ # labels:
+ # password: 'Password'
+ # user:
+ # new:
+ # email: 'E-mail para efetuar o sign in.'
+ # edit:
+ # email: 'E-mail.'
+ # hints:
+ # username: 'User name to sign in.'
+ # password: 'No special characters, please.'
+
4 episode-234/revised/store-after/config/routes.rb
View
@@ -0,0 +1,4 @@
+Store::Application.routes.draw do
+ root to: 'products#index'
+ resources :products
+end
14 episode-234/revised/store-after/db/migrate/20120302190644_create_products.rb
View
@@ -0,0 +1,14 @@
+class CreateProducts < ActiveRecord::Migration
+ def change
+ create_table :products do |t|
+ t.string :name
+ t.decimal :price
+ t.date :released_on
+ t.integer :publisher_id
+ t.integer :rating
+ t.boolean :discontinued, default: false, null: false
+
+ t.timestamps
+ end
+ end
+end
9 episode-234/revised/store-after/db/migrate/20120302190906_create_categories.rb
View
@@ -0,0 +1,9 @@
+class CreateCategories < ActiveRecord::Migration
+ def change
+ create_table :categories do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
10 episode-234/revised/store-after/db/migrate/20120302191003_create_categorizations.rb
View
@@ -0,0 +1,10 @@
+class CreateCategorizations < ActiveRecord::Migration
+ def change
+ create_table :categorizations do |t|
+ t.integer :product_id
+ t.integer :category_id
+
+ t.timestamps
+ end
+ end
+end
9 episode-234/revised/store-after/db/migrate/20120302191013_create_publishers.rb
View
@@ -0,0 +1,9 @@
+class CreatePublishers < ActiveRecord::Migration
+ def change
+ create_table :publishers do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
46 episode-234/revised/store-after/db/schema.rb
View
@@ -0,0 +1,46 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120302191013) do
+
+ create_table "categories", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "categorizations", :force => true do |t|
+ t.integer "product_id"
+ t.integer "category_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "products", :force => true do |t|
+ t.string "name"
+ t.decimal "price"
+ t.date "released_on"
+ t.integer "publisher_id"
+ t.integer "rating"
+ t.boolean "discontinued"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "publishers", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+end
58 episode-234/revised/store-after/db/seeds.rb
View
@@ -0,0 +1,58 @@
+card = Category.create! name: "Card"
+dice = Category.create! name: "Dice"
+party = Category.create! name: "Party"
+strategy = Category.create! name: "Strategy"
+
+days_of_wonder = Publisher.create! name: "Days of Wonder"
+mayfair = Publisher.create! name: "Mayfair Games"
+rio = Publisher.create! name: "Rio Grande Games"
+zman = Publisher.create! name: "Z-Man Games"
+
+Product.create! name: "Settlers of Catan",
+ price: 33.60,
+ publisher: mayfair,
+ categories: [strategy, card, dice],
+ released_on: "1995-02-05",
+ rating: 5
+
+Product.create! name: "Agricola",
+ price: 42.24,
+ publisher: zman,
+ categories: [strategy, card],
+ released_on: "2007-05-18",
+ rating: 5
+
+Product.create! name: "Small World",
+ price: 35.00,
+ publisher: days_of_wonder,
+ categories: [strategy, dice],
+ released_on: "2009-04-12",
+ rating: 4
+
+Product.create! name: "Stone Age",
+ price: 28.99,
+ publisher: rio,
+ categories: [strategy, dice],
+ released_on: "2008-07-15",
+ rating: 5
+
+Product.create! name: "Puerto Rico",
+ price: 27.00,
+ publisher: rio,
+ categories: [strategy],
+ released_on: "2002-03-25",
+ rating: 5
+
+Product.create! name: "Bohnanza",
+ price: 27.00,
+ publisher: rio,
+ categories: [card],
+ released_on: "1997-06-10",
+ rating: 5
+
+Product.create! name: "Ticket to Ride",
+ price: 37.50,
+ publisher: days_of_wonder,
+ categories: [strategy, card],
+ released_on: "2009-04-12",
+ rating: 4
2  episode-234/revised/store-after/doc/README_FOR_APP
View
@@ -0,0 +1,2 @@
+Use this README file to introduce your application and point to useful places in the API for learning more.
+Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
0  episode-234/revised/store-after/lib/assets/.gitkeep
View
No changes.
0  episode-234/revised/store-after/lib/tasks/.gitkeep
View
No changes.
13 episode-234/revised/store-after/lib/templates/erb/scaffold/_form.html.erb
View
@@ -0,0 +1,13 @@
+<%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
+ <%%= f.error_notification %>
+
+ <div class="form-inputs">
+ <%- attributes.each do |attribute| -%>
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
+ <%- end -%>
+ </div>
+
+ <div class="form-actions">
+ <%%= f.button :submit %>
+ </div>
+<%% end %>
0  episode-234/revised/store-after/log/.gitkeep
View
No changes.
26 episode-234/revised/store-after/public/404.html
View
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The page you were looking for doesn't exist (404)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+</body>
+</html>
26 episode-234/revised/store-after/public/422.html
View
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The change you wanted was rejected (422)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+</body>
+</html>
25 episode-234/revised/store-after/public/500.html
View
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>We're sorry, but something went wrong (500)</title>
+ <style type="text/css">
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
+ div.dialog {
+ width: 25em;
+ padding: 0 4em;
+ margin: 4em auto 0 auto;
+ border: 1px solid #ccc;
+ border-right-color: #999;
+ border-bottom-color: #999;
+ }
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
+ </style>
+</head>
+
+<body>
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <h1>We're sorry, but something went wrong.</h1>
+ </div>
+</body>
+</html>
0  episode-234/revised/store-after/public/favicon.ico
View
No changes.
5 episode-234/revised/store-after/public/robots.txt
View
@@ -0,0 +1,5 @@
+# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
+#
+# To ban all spiders from the entire site uncomment the next two lines:
+# User-Agent: *
+# Disallow: /
6 episode-234/revised/store-after/script/rails
View
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
+
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+require File.expand_path('../../config/boot', __FILE__)
+require 'rails/commands'
0  episode-234/revised/store-after/test/fixtures/.gitkeep
View
No changes.
7 episode-234/revised/store-after/test/fixtures/categories.yml
View
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+
+two:
+ name: MyString
9 episode-234/revised/store-after/test/fixtures/categorizations.yml
View
@@ -0,0 +1,9 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ product_id: 1
+ category_id: 1
+
+two:
+ product_id: 1
+ category_id: 1
17 episode-234/revised/store-after/test/fixtures/products.yml
View
@@ -0,0 +1,17 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+ price: 9.99
+ released_on: 2012-03-02
+ publisher_id: 1
+ rating: 1
+ discontinued: false
+
+two:
+ name: MyString
+ price: 9.99
+ released_on: 2012-03-02
+ publisher_id: 1
+ rating: 1
+ discontinued: false
7 episode-234/revised/store-after/test/fixtures/publishers.yml
View
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+
+two:
+ name: MyString
0  episode-234/revised/store-after/test/functional/.gitkeep
View
No changes.
49 episode-234/revised/store-after/test/functional/products_controller_test.rb
View
@@ -0,0 +1,49 @@
+require 'test_helper'
+
+class ProductsControllerTest < ActionController::TestCase
+ setup do
+ @product = products(:one)
+ end
+
+ test "should get index" do
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:products)
+ end
+
+ test "should get new" do
+ get :new
+ assert_response :success
+ end
+
+ test "should create product" do
+ assert_difference('Product.count') do
+ post :create, product: @product.attributes
+ end
+
+ assert_redirected_to product_path(assigns(:product))
+ end
+
+ test "should show product" do
+ get :show, id: @product
+ assert_response :success
+ end
+
+ test "should get edit" do
+ get :edit, id: @product
+ assert_response :success
+ end
+
+ test "should update product" do
+ put :update, id: @product, product: @product.attributes
+ assert_redirected_to product_path(assigns(:product))
+ end
+
+ test "should destroy product" do
+ assert_difference('Product.count', -1) do
+ delete :destroy, id: @product
+ end
+
+ assert_redirected_to products_path
+ end
+end
0  episode-234/revised/store-after/test/integration/.gitkeep
View
No changes.
12 episode-234/revised/store-after/test/performance/browsing_test.rb
View
@@ -0,0 +1,12 @@
+require 'test_helper'
+require 'rails/performance_test_help'
+
+class BrowsingTest < ActionDispatch::PerformanceTest
+ # Refer to the documentation for all available options
+ # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
+ # :output => 'tmp/performance', :formats => [:flat] }
+
+ def test_homepage
+ get '/'
+ end
+end
13 episode-234/revised/store-after/test/test_helper.rb
View
@@ -0,0 +1,13 @@
+ENV["RAILS_ENV"] = "test"
+require File.expand_path('../../config/environment', __FILE__)
+require 'rails/test_help'
+
+class ActiveSupport::TestCase
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
+ #
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
+ # -- they do not yet inherit this setting
+ fixtures :all
+
+ # Add more helper methods to be used by all tests here...
+end
0  episode-234/revised/store-after/test/unit/.gitkeep
View
No changes.
7 episode-234/revised/store-after/test/unit/categorization_test.rb
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CategorizationTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
7 episode-234/revised/store-after/test/unit/category_test.rb
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CategoryTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
4 episode-234/revised/store-after/test/unit/helpers/products_helper_test.rb
View
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ProductsHelperTest < ActionView::TestCase
+end
7 episode-234/revised/store-after/test/unit/product_test.rb
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ProductTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
7 episode-234/revised/store-after/test/unit/publisher_test.rb
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class PublisherTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
0  episode-234/revised/store-after/vendor/assets/javascripts/.gitkeep
View
No changes.
0  episode-234/revised/store-after/vendor/assets/stylesheets/.gitkeep
View
No changes.
0  episode-234/revised/store-after/vendor/plugins/.gitkeep
View
No changes.
15 episode-234/revised/store-before/.gitignore
View
@@ -0,0 +1,15 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
38 episode-234/revised/store-before/Gemfile
View
@@ -0,0 +1,38 @@
+source 'https://rubygems.org'
+
+gem 'rails', '3.2.2'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3'
+
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', '~> 3.2.3'
+ gem 'coffee-rails', '~> 3.2.1'
+
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
+ # gem 'therubyracer'
+
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+
+# To use ActiveModel has_secure_password
+# gem 'bcrypt-ruby', '~> 3.0.0'
+
+# To use Jbuilder templates for JSON
+# gem 'jbuilder'
+
+# Use unicorn as the app server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
111 episode-234/revised/store-before/Gemfile.lock
View
@@ -0,0 +1,111 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ actionmailer (3.2.2)
+ actionpack (= 3.2.2)
+ mail (~> 2.4.0)
+ actionpack (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.1)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ activerecord (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ activesupport (3.2.2)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.0)
+ coffee-rails (3.2.2)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.2.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.2.0)
+ erubis (2.7.0)
+ execjs (1.3.0)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ journey (1.0.3)
+ jquery-rails (2.0.1)
+ railties (>= 3.2.0, < 5.0)
+ thor (~> 0.14)
+ json (1.6.5)
+ mail (2.4.1)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.17.2)
+ multi_json (1.1.0)
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.1)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.2)
+ actionmailer (= 3.2.2)
+ actionpack (= 3.2.2)
+ activerecord (= 3.2.2)
+ activeresource (= 3.2.2)
+ activesupport (= 3.2.2)
+ bundler (~> 1.0)
+ railties (= 3.2.2)
+ railties (3.2.2)
+ actionpack (= 3.2.2)
+ activesupport (= 3.2.2)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ sass (3.1.15)
+ sass-rails (3.2.4)
+ railties (~> 3.2.0)
+ sass (>= 3.1.10)
+ tilt (~> 1.3)
+ sprockets (2.1.2)
+ 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.3)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ coffee-rails (~> 3.2.1)
+ jquery-rails
+ rails (= 3.2.2)
+ sass-rails (~> 3.2.3)
+ sqlite3
+ uglifier (>= 1.0.3)
7 episode-234/revised/store-before/README.rdoc
View
@@ -0,0 +1,7 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:setup
+ rails s
7 episode-234/revised/store-before/Rakefile
View
@@ -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
BIN  episode-234/revised/store-before/app/assets/images/rails.png
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 episode-234/revised/store-before/app/assets/javascripts/application.js
View
@@ -0,0 +1,15 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
+// GO AFTER THE REQUIRES BELOW.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
3  episode-234/revised/store-before/app/assets/javascripts/products.js.coffee
View
@@ -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/
92 episode-234/revised/store-before/app/assets/stylesheets/application.css
View
@@ -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;
+}
3  episode-234/revised/store-before/app/assets/stylesheets/products.css.scss
View
@@ -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/
3  episode-234/revised/store-before/app/controllers/application_controller.rb
View
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
41 episode-234/revised/store-before/app/controllers/products_controller.rb
View
@@ -0,0 +1,41 @@
+class ProductsController < ApplicationController
+ def index
+ @products = Product.order("name")
+ 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
2  episode-234/revised/store-before/app/helpers/application_helper.rb
View
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
2  episode-234/revised/store-before/app/helpers/products_helper.rb
View
@@ -0,0 +1,2 @@
+module ProductsHelper
+end
0  episode-234/revised/store-before/app/mailers/.gitkeep
View
No changes.
0  episode-234/revised/store-before/app/models/.gitkeep
View
No changes.
4 episode-234/revised/store-before/app/models/categorization.rb
View
@@ -0,0 +1,4 @@
+class Categorization < ActiveRecord::Base
+ belongs_to :product
+ belongs_to :category
+end
4 episode-234/revised/store-before/app/models/category.rb
View
@@ -0,0 +1,4 @@
+class Category < ActiveRecord::Base
+ has_many :categorizations
+ has_many :products, through: :categorizations
+end
5 episode-234/revised/store-before/app/models/product.rb
View
@@ -0,0 +1,5 @@
+class Product < ActiveRecord::Base
+ belongs_to :publisher
+ has_many :categorizations
+ has_many :categories, through: :categorizations
+end
3  episode-234/revised/store-before/app/models/publisher.rb
View
@@ -0,0 +1,3 @@
+class Publisher < ActiveRecord::Base
+ has_many :products
+end
17 episode-234/revised/store-before/app/views/layouts/application.html.erb
View
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Store</title>
+ <%= stylesheet_link_tag "application", media: "all" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, id: "flash_#{name}" %>
+ <% end %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
52 episode-234/revised/store-before/app/views/products/_form.html.erb
View
@@ -0,0 +1,52 @@
+<%= form_for(@product) do |f| %>
+ <% if @product.errors.any? %>
+ <div class="error_messages">
+ <h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
+
+ <ul>
+ <% @product.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :price %><br />
+ <%= f.text_field :price %>
+ </div>
+ <div class="field">
+ <%= f.label :released_on %><br />
+ <%= f.date_select :released_on %>
+ </div>
+ <div class="field">
+ <%= f.check_box :discontinued %>
+ <%= f.label :discontinued %>
+ </div>
+ <div class="field">
+ <%= f.label :rating %><br />
+ <%= f.radio_button :rating, 1 %> 1
+ <%= f.radio_button :rating, 2 %> 2
+ <%= f.radio_button :rating, 3 %> 3
+ <%= f.radio_button :rating, 4 %> 4
+ <%= f.radio_button :rating, 5 %> 5
+ </div>
+ <div class="field">
+ <%= f.label :publisher_id %><br />
+ <%= f.collection_select :publisher_id, Publisher.all, :id, :name, include_blank: true %>
+ </div>
+ <div class="field">
+ <%= hidden_field_tag "product[category_ids][]", nil %>
+ <% Category.all.each do |category| %>
+ <%= check_box_tag "product[category_ids][]", category.id, @product.category_ids.include?(category.id), id: dom_id(category) %>
+ <%= label_tag dom_id(category), category.name %><br />
+ <% end %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
3  episode-234/revised/store-before/app/views/products/edit.html.erb
View
@@ -0,0 +1,3 @@
+<h1>Editing Product</h1>
+
+<%= render 'form' %>
14 episode-234/revised/store-before/app/views/products/index.html.erb
View
@@ -0,0 +1,14 @@
+<h1>Games</h1>
+
+<% @products.each do |product| %>
+ <div class="product">
+ <h2><%= link_to product.name, product %></h2>
+ <div class="details">
+ <%= number_to_currency(product.price) %> |
+ <%= product.categories.map(&:name).join(", ") %> |
+ <%= product.publisher.name %>
+ </div>