Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding episode 301

  • Loading branch information...
commit 365744f4f2c86a05a9882eab7cbb4baef26b4085 1 parent ed7b481
@ryanb authored
Showing with 2,181 additions and 0 deletions.
  1. +12 −0 episode-301/README
  2. +5 −0 episode-301/blog-after/.gitignore
  3. +1 −0  episode-301/blog-after/.rspec
  4. +37 −0 episode-301/blog-after/Gemfile
  5. +135 −0 episode-301/blog-after/Gemfile.lock
  6. +9 −0 episode-301/blog-after/README
  7. +7 −0 episode-301/blog-after/Rakefile
  8. BIN  episode-301/blog-after/app/assets/images/rails.png
  9. +9 −0 episode-301/blog-after/app/assets/javascripts/application.js
  10. +3 −0  episode-301/blog-after/app/assets/javascripts/articles.js.coffee
  11. +3 −0  episode-301/blog-after/app/assets/javascripts/comments.js.coffee
  12. +123 −0 episode-301/blog-after/app/assets/stylesheets/application.css
  13. +3 −0  episode-301/blog-after/app/assets/stylesheets/articles.css.scss
  14. +3 −0  episode-301/blog-after/app/assets/stylesheets/comments.css.scss
  15. +3 −0  episode-301/blog-after/app/controllers/application_controller.rb
  16. +10 −0 episode-301/blog-after/app/controllers/articles_controller.rb
  17. +14 −0 episode-301/blog-after/app/controllers/comments_controller.rb
  18. +2 −0  episode-301/blog-after/app/helpers/application_helper.rb
  19. +2 −0  episode-301/blog-after/app/helpers/articles_helper.rb
  20. +2 −0  episode-301/blog-after/app/helpers/comments_helper.rb
  21. 0  episode-301/blog-after/app/mailers/.gitkeep
  22. 0  episode-301/blog-after/app/models/.gitkeep
  23. +3 −0  episode-301/blog-after/app/models/article.rb
  24. +21 −0 episode-301/blog-after/app/models/comment.rb
  25. +12 −0 episode-301/blog-after/app/views/articles/index.html.erb
  26. +22 −0 episode-301/blog-after/app/views/articles/show.html.erb
  27. +27 −0 episode-301/blog-after/app/views/comments/_form.html.erb
  28. +3 −0  episode-301/blog-after/app/views/comments/new.html.erb
  29. +17 −0 episode-301/blog-after/app/views/layouts/application.html.erb
  30. +4 −0 episode-301/blog-after/config.ru
  31. +48 −0 episode-301/blog-after/config/application.rb
  32. +6 −0 episode-301/blog-after/config/boot.rb
  33. +25 −0 episode-301/blog-after/config/database.yml
  34. +5 −0 episode-301/blog-after/config/environment.rb
  35. +30 −0 episode-301/blog-after/config/environments/development.rb
  36. +60 −0 episode-301/blog-after/config/environments/production.rb
  37. +39 −0 episode-301/blog-after/config/environments/test.rb
  38. +7 −0 episode-301/blog-after/config/initializers/backtrace_silencers.rb
  39. +10 −0 episode-301/blog-after/config/initializers/inflections.rb
  40. +5 −0 episode-301/blog-after/config/initializers/mime_types.rb
  41. +7 −0 episode-301/blog-after/config/initializers/secret_token.rb
  42. +8 −0 episode-301/blog-after/config/initializers/session_store.rb
  43. +14 −0 episode-301/blog-after/config/initializers/wrap_parameters.rb
  44. +5 −0 episode-301/blog-after/config/locales/en.yml
  45. +5 −0 episode-301/blog-after/config/routes.rb
  46. +10 −0 episode-301/blog-after/db/migrate/20111118235239_create_articles.rb
  47. +12 −0 episode-301/blog-after/db/migrate/20111118235527_create_comments.rb
  48. +32 −0 episode-301/blog-after/db/schema.rb
  49. +11 −0 episode-301/blog-after/db/seeds.rb
  50. +2 −0  episode-301/blog-after/doc/README_FOR_APP
  51. 0  episode-301/blog-after/lib/assets/.gitkeep
  52. 0  episode-301/blog-after/lib/tasks/.gitkeep
  53. 0  episode-301/blog-after/log/.gitkeep
  54. +26 −0 episode-301/blog-after/public/404.html
  55. +26 −0 episode-301/blog-after/public/422.html
  56. +26 −0 episode-301/blog-after/public/500.html
  57. 0  episode-301/blog-after/public/favicon.ico
  58. +5 −0 episode-301/blog-after/public/robots.txt
  59. +6 −0 episode-301/blog-after/script/rails
  60. +17 −0 episode-301/blog-after/spec/models/comment_spec.rb
  61. +33 −0 episode-301/blog-after/spec/spec_helper.rb
  62. 0  episode-301/blog-after/vendor/assets/stylesheets/.gitkeep
  63. 0  episode-301/blog-after/vendor/plugins/.gitkeep
  64. +5 −0 episode-301/blog-before/.gitignore
  65. +1 −0  episode-301/blog-before/.rspec
  66. +35 −0 episode-301/blog-before/Gemfile
  67. +129 −0 episode-301/blog-before/Gemfile.lock
  68. +9 −0 episode-301/blog-before/README
  69. +7 −0 episode-301/blog-before/Rakefile
  70. BIN  episode-301/blog-before/app/assets/images/rails.png
  71. +9 −0 episode-301/blog-before/app/assets/javascripts/application.js
  72. +3 −0  episode-301/blog-before/app/assets/javascripts/articles.js.coffee
  73. +3 −0  episode-301/blog-before/app/assets/javascripts/comments.js.coffee
  74. +123 −0 episode-301/blog-before/app/assets/stylesheets/application.css
  75. +3 −0  episode-301/blog-before/app/assets/stylesheets/articles.css.scss
  76. +3 −0  episode-301/blog-before/app/assets/stylesheets/comments.css.scss
  77. +3 −0  episode-301/blog-before/app/controllers/application_controller.rb
  78. +10 −0 episode-301/blog-before/app/controllers/articles_controller.rb
  79. +14 −0 episode-301/blog-before/app/controllers/comments_controller.rb
  80. +2 −0  episode-301/blog-before/app/helpers/application_helper.rb
  81. +2 −0  episode-301/blog-before/app/helpers/articles_helper.rb
  82. +2 −0  episode-301/blog-before/app/helpers/comments_helper.rb
  83. 0  episode-301/blog-before/app/mailers/.gitkeep
  84. 0  episode-301/blog-before/app/models/.gitkeep
  85. +3 −0  episode-301/blog-before/app/models/article.rb
  86. +21 −0 episode-301/blog-before/app/models/comment.rb
  87. +12 −0 episode-301/blog-before/app/views/articles/index.html.erb
  88. +22 −0 episode-301/blog-before/app/views/articles/show.html.erb
  89. +27 −0 episode-301/blog-before/app/views/comments/_form.html.erb
  90. +3 −0  episode-301/blog-before/app/views/comments/new.html.erb
  91. +17 −0 episode-301/blog-before/app/views/layouts/application.html.erb
  92. +4 −0 episode-301/blog-before/config.ru
  93. +48 −0 episode-301/blog-before/config/application.rb
  94. +6 −0 episode-301/blog-before/config/boot.rb
  95. +25 −0 episode-301/blog-before/config/database.yml
  96. +5 −0 episode-301/blog-before/config/environment.rb
  97. +30 −0 episode-301/blog-before/config/environments/development.rb
  98. +60 −0 episode-301/blog-before/config/environments/production.rb
  99. +39 −0 episode-301/blog-before/config/environments/test.rb
  100. +7 −0 episode-301/blog-before/config/initializers/backtrace_silencers.rb
  101. +10 −0 episode-301/blog-before/config/initializers/inflections.rb
  102. +5 −0 episode-301/blog-before/config/initializers/mime_types.rb
  103. +7 −0 episode-301/blog-before/config/initializers/secret_token.rb
  104. +8 −0 episode-301/blog-before/config/initializers/session_store.rb
  105. +14 −0 episode-301/blog-before/config/initializers/wrap_parameters.rb
  106. +5 −0 episode-301/blog-before/config/locales/en.yml
  107. +5 −0 episode-301/blog-before/config/routes.rb
  108. +10 −0 episode-301/blog-before/db/migrate/20111118235239_create_articles.rb
  109. +12 −0 episode-301/blog-before/db/migrate/20111118235527_create_comments.rb
  110. +32 −0 episode-301/blog-before/db/schema.rb
  111. +11 −0 episode-301/blog-before/db/seeds.rb
  112. +2 −0  episode-301/blog-before/doc/README_FOR_APP
  113. 0  episode-301/blog-before/lib/assets/.gitkeep
  114. 0  episode-301/blog-before/lib/tasks/.gitkeep
  115. 0  episode-301/blog-before/log/.gitkeep
  116. +26 −0 episode-301/blog-before/public/404.html
  117. +26 −0 episode-301/blog-before/public/422.html
  118. +26 −0 episode-301/blog-before/public/500.html
  119. 0  episode-301/blog-before/public/favicon.ico
  120. +5 −0 episode-301/blog-before/public/robots.txt
  121. +6 −0 episode-301/blog-before/script/rails
  122. +66 −0 episode-301/blog-before/spec/models/comment_spec.rb
  123. +33 −0 episode-301/blog-before/spec/spec_helper.rb
  124. 0  episode-301/blog-before/vendor/assets/stylesheets/.gitkeep
  125. 0  episode-301/blog-before/vendor/plugins/.gitkeep
  126. +4 −0 episode-301/url_formatter/.gitignore
  127. +1 −0  episode-301/url_formatter/.rspec
  128. +4 −0 episode-301/url_formatter/Gemfile
  129. +20 −0 episode-301/url_formatter/LICENSE
  130. +34 −0 episode-301/url_formatter/README.md
  131. +6 −0 episode-301/url_formatter/Rakefile
  132. +17 −0 episode-301/url_formatter/lib/url_formatter.rb
  133. +10 −0 episode-301/url_formatter/lib/url_formatter/model_additions.rb
  134. +9 −0 episode-301/url_formatter/lib/url_formatter/railtie.rb
  135. +3 −0  episode-301/url_formatter/lib/url_formatter/version.rb
  136. +2 −0  episode-301/url_formatter/spec/spec_helper.rb
  137. +22 −0 episode-301/url_formatter/spec/url_formatter/model_additions_spec.rb
  138. +53 −0 episode-301/url_formatter/spec/url_formatter_spec.rb
  139. +23 −0 episode-301/url_formatter/url_formatter.gemspec
View
12 episode-301/README
@@ -0,0 +1,12 @@
+RailsCasts Episode #301: Extracting a Ruby Gem
+
+http://railscasts.com/episodes/301-extracting-a-ruby-gem
+
+Commands used in episode
+
+ bundle gem url_formatter
+ bundle
+ echo "--color" > .rspec
+ mkdir -p spec/url_formatter
+ touch spec/spec_helper.rb
+ rake
View
5 episode-301/blog-after/.gitignore
@@ -0,0 +1,5 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
+.sass-cache/
View
1  episode-301/blog-after/.rspec
@@ -0,0 +1 @@
+--colour
View
37 episode-301/blog-after/Gemfile
@@ -0,0 +1,37 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.1.1'
+
+# 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.1.4'
+ gem 'coffee-rails', '~> 3.1.1'
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+
+# To use ActiveModel has_secure_password
+# gem 'bcrypt-ruby', '~> 3.0.0'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+group :test, :development do
+ gem 'rspec-rails'
+end
+
+gem 'url_formatter', path: '~/code/url_formatter'
View
135 episode-301/blog-after/Gemfile.lock
@@ -0,0 +1,135 @@
+PATH
+ remote: ~/code/url_formatter
+ specs:
+ url_formatter (0.0.1.alpha)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ 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.3)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ execjs (1.2.9)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.18)
+ 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)
+ 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.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)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
+ rspec-rails (2.7.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.7.0)
+ sass (3.1.10)
+ 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.4)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+ uglifier (1.1.0)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ coffee-rails (~> 3.1.1)
+ jquery-rails
+ rails (= 3.1.1)
+ rspec-rails
+ sass-rails (~> 3.1.4)
+ sqlite3
+ uglifier (>= 1.0.3)
+ url_formatter!
View
9 episode-301/blog-after/README
@@ -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 later to run.
View
7 episode-301/blog-after/Rakefile
@@ -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__)
+
+Blog::Application.load_tasks
View
BIN  episode-301/blog-after/app/assets/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
9 episode-301/blog-after/app/assets/javascripts/application.js
@@ -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 .
View
3  episode-301/blog-after/app/assets/javascripts/articles.js.coffee
@@ -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/
View
3  episode-301/blog-after/app/assets/javascripts/comments.js.coffee
@@ -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/
View
123 episode-301/blog-after/app/assets/stylesheets/application.css
@@ -0,0 +1,123 @@
+/*
+ * 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;
+}
+
+.field_with_errors {
+ 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-bottom: 0;
+}
+
+form .field, form .actions {
+ margin: 12px 0;
+}
+
+#articles h2 {
+ font-size: 16px;
+ margin-bottom: 2px;
+}
+
+#articles h2 .comments {
+ font-size: 12px;
+ font-weight: normal;
+}
+
+#articles .date {
+ font-style: italic;
+ color: #333;
+}
+
+#comments {
+ font-size: 12px;
+ background-color: #EEE;
+ padding: 0 20px;
+ width: 325px;
+ border: solid 1px #777;
+}
+
+.comment {
+ border-bottom: solid 1px #999;
+ margin: 15px 0;
+}
+
+.comment:last-child {
+ border-bottom: none;
+}
+
+.comment .author_name {
+ font-weight: bold;
+}
View
3  episode-301/blog-after/app/assets/stylesheets/articles.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the articles controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  episode-301/blog-after/app/assets/stylesheets/comments.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the comments controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  episode-301/blog-after/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
View
10 episode-301/blog-after/app/controllers/articles_controller.rb
@@ -0,0 +1,10 @@
+class ArticlesController < ApplicationController
+ def index
+ @articles = Article.all
+ end
+
+ def show
+ @article = Article.find(params[:id])
+ @comment = Comment.new(article_id: @article.id)
+ end
+end
View
14 episode-301/blog-after/app/controllers/comments_controller.rb
@@ -0,0 +1,14 @@
+class CommentsController < ApplicationController
+ def new
+ @comment = Comment.new
+ end
+
+ def create
+ @comment = Comment.new(params[:comment])
+ if @comment.save
+ redirect_to @comment.article, notice: "Successfully created comment."
+ else
+ render :new
+ end
+ end
+end
View
2  episode-301/blog-after/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
View
2  episode-301/blog-after/app/helpers/articles_helper.rb
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
View
2  episode-301/blog-after/app/helpers/comments_helper.rb
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
View
0  episode-301/blog-after/app/mailers/.gitkeep
No changes.
View
0  episode-301/blog-after/app/models/.gitkeep
No changes.
View
3  episode-301/blog-after/app/models/article.rb
@@ -0,0 +1,3 @@
+class Article < ActiveRecord::Base
+ has_many :comments
+end
View
21 episode-301/blog-after/app/models/comment.rb
@@ -0,0 +1,21 @@
+class Comment < ActiveRecord::Base
+ belongs_to :article
+
+ def self.format_url(url)
+ if url.to_s !~ url_regexp && "http://#{url}" =~ url_regexp
+ "http://#{url}"
+ else
+ url
+ end
+ end
+
+ def self.url_regexp
+ /^https?:\/\/([^\s:@]+:[^\s:@]*@)?[-[[:alnum:]]]+(\.[-[[:alnum:]]]+)+\.?(:\d{1,5})?([\/?]\S*)?$/iux
+ end
+
+ before_validation do
+ self.website = self.class.format_url(website)
+ end
+
+ validates_format_of :website, with: url_regexp, message: "is not a valid URL"
+end
View
12 episode-301/blog-after/app/views/articles/index.html.erb
@@ -0,0 +1,12 @@
+<h1>Articles</h1>
+
+<div id="articles">
+<% for article in @articles %>
+ <h2>
+ <%= link_to article.name, article %>
+ <span class="comments">(<%= pluralize(article.comments.size, 'comment') %>)</span>
+ </h2>
+ <div class="date">on <%= article.created_at.strftime('%b %d, %Y') %></div>
+ <div class="content"><%= simple_format(article.content) %></div>
+<% end %>
+</div>
View
22 episode-301/blog-after/app/views/articles/show.html.erb
@@ -0,0 +1,22 @@
+<h1><%= @article.name %></h1>
+
+<%= simple_format @article.content %>
+
+<p><%= link_to "Back to Articles", articles_path %></p>
+
+<% unless @article.comments.empty? %>
+ <h2><%= pluralize(@article.comments.size, 'comment') %></h2>
+
+ <div id="comments">
+ <% for comment in @article.comments %>
+ <div class="comment">
+ <strong><%= link_to_unless comment.website.blank?, comment.name, comment.website %></strong>
+ <em>on <%= comment.created_at.strftime('%b %d, %Y') %></em>
+ <%= simple_format comment.content %>
+ </div>
+ <% end %>
+ </div>
+<% end %>
+
+<h3>Add your comment:</h3>
+<%= render "comments/form" %>
View
27 episode-301/blog-after/app/views/comments/_form.html.erb
@@ -0,0 +1,27 @@
+<%= form_for @comment do |f| %>
+ <% if @comment.errors.any? %>
+ <div class="error_messages">
+ <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
+ <ul>
+ <% @comment.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <%= f.hidden_field :article_id %>
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :website, "Website URL" %><br />
+ <%= f.text_field :website %>
+ </div>
+ <div class="field">
+ <%= f.label :content, "Comment" %><br />
+ <%= f.text_area :content, :rows => 12, :cols => 35 %>
+ </div>
+ <div class="actions"><%= f.submit %></div>
+<% end %>
View
3  episode-301/blog-after/app/views/comments/new.html.erb
@@ -0,0 +1,3 @@
+<h1>New Comment</h1>
+
+<%= render 'form' %>
View
17 episode-301/blog-after/app/views/layouts/application.html.erb
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Blog</title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tag %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
View
4 episode-301/blog-after/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Blog::Application
View
48 episode-301/blog-after/config/application.rb
@@ -0,0 +1,48 @@
+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 Blog
+ 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]
+
+ # 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
View
6 episode-301/blog-after/config/boot.rb
@@ -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'])
View
25 episode-301/blog-after/config/database.yml
@@ -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
View
5 episode-301/blog-after/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Blog::Application.initialize!
View
30 episode-301/blog-after/config/environments/development.rb
@@ -0,0 +1,30 @@
+Blog::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
+
+ # Do not compress assets
+ config.assets.compress = false
+
+ # Expands the lines which load the assets
+ config.assets.debug = true
+end
View
60 episode-301/blog-after/config/environments/production.rb
@@ -0,0 +1,60 @@
+Blog::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
+
+ # Use a different logger for distributed setups
+ # config.logger = 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
+end
View
39 episode-301/blog-after/config/environments/test.rb
@@ -0,0 +1,39 @@
+Blog::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
+
+ # Use SQL instead of Active Record's schema dumper when creating the test 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
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
View
7 episode-301/blog-after/config/initializers/backtrace_silencers.rb
@@ -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!
View
10 episode-301/blog-after/config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# 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
View
5 episode-301/blog-after/config/initializers/mime_types.rb
@@ -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
View
7 episode-301/blog-after/config/initializers/secret_token.rb
@@ -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.
+Blog::Application.config.secret_token = '033e304131cfa206cc39e71815a1cc81f68a5e2912e0d1cb8ba8afbf5d4a0b032afca70b0854f6719f7856845c48cbc2bc295be0fe9ca43d4f806d5e44a8afe9'
View
8 episode-301/blog-after/config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Blog::Application.config.session_store :cookie_store, key: '_blog_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")
+# Blog::Application.config.session_store :active_record_store
View
14 episode-301/blog-after/config/initializers/wrap_parameters.rb
@@ -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
View
5 episode-301/blog-after/config/locales/en.yml
@@ -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"
View
5 episode-301/blog-after/config/routes.rb
@@ -0,0 +1,5 @@
+Blog::Application.routes.draw do
+ root to: 'articles#index'
+ resources :articles
+ resources :comments
+end
View
10 episode-301/blog-after/db/migrate/20111118235239_create_articles.rb
@@ -0,0 +1,10 @@
+class CreateArticles < ActiveRecord::Migration
+ def change
+ create_table :articles do |t|
+ t.string :name
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
View
12 episode-301/blog-after/db/migrate/20111118235527_create_comments.rb
@@ -0,0 +1,12 @@
+class CreateComments < ActiveRecord::Migration
+ def change
+ create_table :comments do |t|
+ t.integer :article_id
+ t.string :name
+ t.string :website
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
View
32 episode-301/blog-after/db/schema.rb
@@ -0,0 +1,32 @@
+# 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 => 20111118235527) do
+
+ create_table "articles", :force => true do |t|
+ t.string "name"
+ t.text "content"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "comments", :force => true do |t|
+ t.integer "article_id"
+ t.string "name"
+ t.string "website"
+ t.text "content"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
View
11 episode-301/blog-after/db/seeds.rb
@@ -0,0 +1,11 @@
+Article.create! name: "Batman", content: <<-ARTICLE
+(from Wikipedia)
+
+Batman is a fictional character created by the artist Bob Kane and writer Bill Finger. A comic book superhero, Batman first appeared in Detective Comics #27 (May 1939), and since then has appeared primarily in publications by DC Comics. Originally referred to as "The Bat-Man" and still referred to at times as "The Batman", he is additionally known as "The Caped Crusader", "The Dark Knight", and the "World's Greatest Detective," among other titles.
+ARTICLE
+
+Article.create! name: "Superman", content: <<-ARTICLE
+(from Wikipedia)
+
+Superman is a fictional comic book superhero appearing in publications by DC Comics, widely considered to be an American cultural icon. Created by American writer Jerry Siegel and Canadian-born American artist Joe Shuster in 1932 while both were living in Cleveland, Ohio, and sold to Detective Comics, Inc. (later DC Comics) in 1938, the character first appeared in Action Comics #1 (June 1938) and subsequently appeared in various radio serials, television programs, films, newspaper strips, and video games. With the success of his adventures, Superman helped to create the superhero genre and establish its primacy within the American comic book. The character's appearance is distinctive and iconic: a blue, red and yellow costume, complete with cape, with a stylized "S" shield on his chest. This shield is now typically used across media to symbolize the character.
+ARTICLE
View
2  episode-301/blog-after/doc/README_FOR_APP
@@ -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.
View
0  episode-301/blog-after/lib/assets/.gitkeep
No changes.
View
0  episode-301/blog-after/lib/tasks/.gitkeep
No changes.
View
0  episode-301/blog-after/log/.gitkeep
No changes.
View
26 episode-301/blog-after/public/404.html
@@ -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>
View
26 episode-301/blog-after/public/422.html
@@ -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>
View
26 episode-301/blog-after/public/500.html
@@ -0,0 +1,26 @@
+<!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>
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
+ </div>
+</body>
+</html>
View
0  episode-301/blog-after/public/favicon.ico
No changes.
View
5 episode-301/blog-after/public/robots.txt
@@ -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: /
View
6 episode-301/blog-after/script/rails
@@ -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'
View
17 episode-301/blog-after/spec/models/comment_spec.rb
@@ -0,0 +1,17 @@
+# encoding: utf-8
+require 'spec_helper'
+
+describe Comment do
+ it "adds http:// to URL upon saving" do
+ Comment.create!(website: "example.com").website.should eq("http://example.com")
+ Comment.create!(website: "http://example.com").website.should eq("http://example.com")
+ end
+
+ it "validates URL format" do
+ comment = Comment.new(website: "foo bar")
+ comment.should_not be_valid
+ comment.errors[:website].should eq(["is not a valid URL"])
+ comment.website = "example.com"
+ comment.should be_valid
+ end
+end
View
33 episode-301/blog-after/spec/spec_helper.rb
@@ -0,0 +1,33 @@
+# This file is copied to spec/ when you run 'rails generate rspec:install'
+ENV["RAILS_ENV"] ||= 'test'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
+require 'rspec/autorun'
+
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+end
View
0  episode-301/blog-after/vendor/assets/stylesheets/.gitkeep
No changes.
View
0  episode-301/blog-after/vendor/plugins/.gitkeep
No changes.
View
5 episode-301/blog-before/.gitignore
@@ -0,0 +1,5 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
+.sass-cache/
View
1  episode-301/blog-before/.rspec
@@ -0,0 +1 @@
+--colour
View
35 episode-301/blog-before/Gemfile
@@ -0,0 +1,35 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.1.1'
+
+# 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.1.4'
+ gem 'coffee-rails', '~> 3.1.1'
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+
+# To use ActiveModel has_secure_password
+# gem 'bcrypt-ruby', '~> 3.0.0'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+group :test, :development do
+ gem 'rspec-rails'
+end
View
129 episode-301/blog-before/Gemfile.lock
@@ -0,0 +1,129 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ 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.3)
+ diff-lcs (1.1.3)
+ erubis (2.7.0)
+ execjs (1.2.9)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.18)
+ 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)
+ 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.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)
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
+ rspec-rails (2.7.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.7.0)
+ sass (3.1.10)
+ 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.4)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.31)
+ uglifier (1.1.0)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ coffee-rails (~> 3.1.1)
+ jquery-rails
+ rails (= 3.1.1)
+ rspec-rails
+ sass-rails (~> 3.1.4)
+ sqlite3
+ uglifier (>= 1.0.3)
View
9 episode-301/blog-before/README
@@ -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 later to run.
View
7 episode-301/blog-before/Rakefile
@@ -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__)
+
+Blog::Application.load_tasks
View
BIN  episode-301/blog-before/app/assets/images/rails.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
9 episode-301/blog-before/app/assets/javascripts/application.js
@@ -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 .
View
3  episode-301/blog-before/app/assets/javascripts/articles.js.coffee
@@ -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/
View
3  episode-301/blog-before/app/assets/javascripts/comments.js.coffee
@@ -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/
View
123 episode-301/blog-before/app/assets/stylesheets/application.css
@@ -0,0 +1,123 @@
+/*
+ * 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;
+}
+
+.field_with_errors {
+ 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-bottom: 0;
+}
+
+form .field, form .actions {
+ margin: 12px 0;
+}
+
+#articles h2 {
+ font-size: 16px;
+ margin-bottom: 2px;
+}
+
+#articles h2 .comments {
+ font-size: 12px;
+ font-weight: normal;
+}
+
+#articles .date {
+ font-style: italic;
+ color: #333;
+}
+
+#comments {
+ font-size: 12px;
+ background-color: #EEE;
+ padding: 0 20px;
+ width: 325px;
+ border: solid 1px #777;
+}
+
+.comment {
+ border-bottom: solid 1px #999;
+ margin: 15px 0;
+}
+
+.comment:last-child {
+ border-bottom: none;
+}
+
+.comment .author_name {
+ font-weight: bold;
+}
View
3  episode-301/blog-before/app/assets/stylesheets/articles.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the articles controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  episode-301/blog-before/app/assets/stylesheets/comments.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the comments controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  episode-301/blog-before/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
View
10 episode-301/blog-before/app/controllers/articles_controller.rb
@@ -0,0 +1,10 @@
+class ArticlesController < ApplicationController
+ def index
+ @articles = Article.all
+ end
+
+ def show
+ @article = Article.find(params[:id])
+ @comment = Comment.new(article_id: @article.id)
+ end
+end
View
14 episode-301/blog-before/app/controllers/comments_controller.rb
@@ -0,0 +1,14 @@
+class CommentsController < ApplicationController
+ def new
+ @comment = Comment.new
+ end
+
+ def create
+ @comment = Comment.new(params[:comment])
+ if @comment.save
+ redirect_to @comment.article, notice: "Successfully created comment."
+ else
+ render :new
+ end
+ end
+end
View
2  episode-301/blog-before/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
View
2  episode-301/blog-before/app/helpers/articles_helper.rb
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
View
2  episode-301/blog-before/app/helpers/comments_helper.rb
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
View
0  episode-301/blog-before/app/mailers/.gitkeep
No changes.
View
0  episode-301/blog-before/app/models/.gitkeep
No changes.
View
3  episode-301/blog-before/app/models/article.rb
@@ -0,0 +1,3 @@
+class Article < ActiveRecord::Base
+ has_many :comments
+end
View
21 episode-301/blog-before/app/models/comment.rb
@@ -0,0 +1,21 @@
+class Comment < ActiveRecord::Base
+ belongs_to :article
+
+ def self.format_url(url)
+ if url.to_s !~ url_regexp && "http://#{url}" =~ url_regexp
+ "http://#{url}"
+ else
+ url
+ end
+ end
+
+ def self.url_regexp
+ /^https?:\/\/([^\s:@]+:[^\s:@]*@)?[-[[:alnum:]]]+(\.[-[[:alnum:]]]+)+\.?(:\d{1,5})?([\/?]\S*)?$/iux
+ end
+
+ before_validation do
+ self.website = self.class.format_url(website)
+ end
+
+ validates_format_of :website, with: url_regexp, message: "is not a valid URL"
+end
View
12 episode-301/blog-before/app/views/articles/index.html.erb
@@ -0,0 +1,12 @@
+<h1>Articles</h1>
+
+<div id="articles">
+<% for article in @articles %>
+ <h2>
+ <%= link_to article.name, article %>
+ <span class="comments">(<%= pluralize(article.comments.size, 'comment') %>)</span>
+ </h2>
+ <div class="date">on <%= article.created_at.strftime('%b %d, %Y') %></div>
+ <div class="content"><%= simple_format(article.content) %></div>
+<% end %>
+</div>
View
22 episode-301/blog-before/app/views/articles/show.html.erb
@@ -0,0 +1,22 @@
+<h1><%= @article.name %></h1>
+
+<%= simple_format @article.content %>
+
+<p><%= link_to "Back to Articles", articles_path %></p>
+
+<% unless @article.comments.empty? %>
+ <h2><%= pluralize(@article.comments.size, 'comment') %></h2>
+
+ <div id="comments">
+ <% for comment in @article.comments %>
+ <div class="comment">
+ <strong><%= link_to_unless comment.website.blank?, comment.name, comment.website %></strong>
+ <em>on <%= comment.created_at.strftime('%b %d, %Y') %></em>
+ <%= simple_format comment.content %>
+ </div>
+ <% end %>
+ </div>
+<% end %>
+
+<h3>Add your comment:</h3>
+<%= render "comments/form" %>
View
27 episode-301/blog-before/app/views/comments/_form.html.erb
@@ -0,0 +1,27 @@
+<%= form_for @comment do |f| %>
+ <% if @comment.errors.any? %>
+ <div class="error_messages">
+ <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
+ <ul>
+ <% @comment.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <%= f.hidden_field :article_id %>
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :website, "Website URL" %><br />
+ <%= f.text_field :website %>
+ </div>
+ <div class="field">
+ <%= f.label :content, "Comment" %><br />
+ <%= f.text_area :content, :rows => 12, :cols => 35 %>
+ </div>
+ <div class="actions"><%= f.submit %></div>
+<% end %>
View
3  episode-301/blog-before/app/views/comments/new.html.erb
@@ -0,0 +1,3 @@
+<h1>New Comment</h1>
+
+<%= render 'form' %>
View
17 episode-301/blog-before/app/views/layouts/application.html.erb
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Blog</title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tag %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
View
4 episode-301/blog-before/config.ru
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Blog::Application
View
48 episode-301/blog-before/config/application.rb
@@ -0,0 +1,48 @@
+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 Blog
+ 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]
+
+ # 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
View
6 episode-301/blog-before/config/boot.rb
@@ -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'])
View
25 episode-301/blog-before/config/database.yml
@@ -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
View
5 episode-301/blog-before/config/environment.rb
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Blog::Application.initialize!
View
30 episode-301/blog-before/config/environments/development.rb
@@ -0,0 +1,30 @@
+Blog::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
+
+ # Do not compress assets
+ config.assets.compress = false
+
+ # Expands the lines which load the assets
+ config.assets.debug = true
+end
View
60 episode-301/blog-before/config/environments/production.rb
@@ -0,0 +1,60 @@
+Blog::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
+
+ # Use a different logger for distributed setups
+ # config.logger = 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
+end
View
39 episode-301/blog-before/config/environments/test.rb
@@ -0,0 +1,39 @@
+Blog::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
+
+ # Use SQL instead of Active Record's schema dumper when creating the test 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
+
+ # Print deprecation notices to the stderr
+ config.active_support.deprecation = :stderr
+end
View
7 episode-301/blog-before/config/initializers/backtrace_silencers.rb
@@ -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!
View
10 episode-301/blog-before/config/initializers/inflections.rb
@@ -0,0 +1,10 @@
+# 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
View
5 episode-301/blog-before/config/initializers/mime_types.rb
@@ -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
View
7 episode-301/blog-before/config/initializers/secret_token.rb
@@ -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.
+Blog::Application.config.secret_token = '033e304131cfa206cc39e71815a1cc81f68a5e2912e0d1cb8ba8afbf5d4a0b032afca70b0854f6719f7856845c48cbc2bc295be0fe9ca43d4f806d5e44a8afe9'
View
8 episode-301/blog-before/config/initializers/session_store.rb
@@ -0,0 +1,8 @@
+# Be sure to restart your server when you modify this file.
+
+Blog::Application.config.session_store :cookie_store, key: '_blog_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")
+# Blog::Application.config.session_store :active_record_store
View
14 episode-301/blog-before/config/initializers/wrap_parameters.rb
@@ -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
View
5 episode-301/blog-before/config/locales/en.yml
@@ -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"
View
5 episode-301/blog-before/config/routes.rb
@@ -0,0 +1,5 @@
+Blog::Application.routes.draw do
+ root to: 'articles#index'
+ resources :articles
+ resources :comments
+end
View
10 episode-301/blog-before/db/migrate/20111118235239_create_articles.rb
@@ -0,0 +1,10 @@
+class CreateArticles < ActiveRecord::Migration
+ def change
+ create_table :articles do |t|
+ t.string :name
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
View
12 episode-301/blog-before/db/migrate/20111118235527_create_comments.rb
@@ -0,0 +1,12 @@
+class CreateComments < ActiveRecord::Migration
+ def change
+ create_table :comments do |t|
+ t.integer :article_id
+ t.string :name
+ t.string :website
+ t.text :content
+
+ t.timestamps
+ end
+ end
+end
View
32 episode-301/blog-before/db/schema.rb
@@ -0,0 +1,32 @@
+# 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 => 20111118235527) do
+
+ create_table "articles", :force => true do |t|
+ t.string "name"
+ t.text "content"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "comments", :force => true do |t|
+ t.integer "article_id"
+ t.string "name"
+ t.string "website"
+ t.text "content"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
View
11 episode-301/blog-before/db/seeds.rb
@@ -0,0 +1,11 @@
+Article.create! name: "Batman", content: <<-ARTICLE
+(from Wikipedia)
+
+Batman is a fictional character created by the artist Bob Kane and writer Bill Finger. A comic book superhero, Batman first appeared in Detective Comics #27 (May 1939), and since then has appeared primarily in publications by DC Comics. Originally referred to as "The Bat-Man" and still referred to at times as "The Batman", he is additionally known as "The Caped Crusader", "The Dark Knight", and the "World's Greatest Detective," among other titles.
+ARTICLE
+
+Article.create! name: "Superman", content: <<-ARTICLE
+(from Wikipedia)
+
+Superman is a fictional comic book superhero appearing in publications by DC Comics, widely considered to be an American cultural icon. Created by American writer Jerry Siegel and Canadian-born American artist Joe Shuster in 1932 while both were living in Cleveland, Ohio, and sold to Detective Comics, Inc. (later DC Comics) in 1938, the character first appeared in Action Comics #1 (June 1938) and subsequently appeared in various radio serials, television programs, films, newspaper strips, and video games. With the success of his adventures, Superman helped to create the superhero genre and establish its primacy within the American comic book. The character's appearance is distinctive and iconic: a blue, red and yellow costume, complete with cape, with a stylized "S" shield on his chest. This shield is now typically used across media to symbolize the character.
+ARTICLE
View
2  episode-301/blog-before/doc/README_FOR_APP
@@ -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.
View
0  episode-301/blog-before/lib/assets/.gitkeep
No changes.
View
0  episode-301/blog-before/lib/tasks/.gitkeep
No changes.
View
0  episode-301/blog-before/log/.gitkeep
No changes.