Permalink
Browse files

adding episode 280

  • Loading branch information...
1 parent 86c3254 commit 5a1839c26a63b94d28fbff90209c94f0fa895aa1 @ryanb committed Aug 22, 2011
Showing with 20,477 additions and 0 deletions.
  1. +10 −0 episode-280/README
  2. +4 −0 episode-280/blog-after/.gitignore
  3. +6 −0 episode-280/blog-after/Gemfile
  4. +91 −0 episode-280/blog-after/Gemfile.lock
  5. +8 −0 episode-280/blog-after/README
  6. +7 −0 episode-280/blog-after/Rakefile
  7. +3 −0 episode-280/blog-after/app/controllers/application_controller.rb
  8. +42 −0 episode-280/blog-after/app/controllers/articles_controller.rb
  9. +7 −0 episode-280/blog-after/app/controllers/comments_controller.rb
  10. +2 −0 episode-280/blog-after/app/helpers/application_helper.rb
  11. +2 −0 episode-280/blog-after/app/helpers/articles_helper.rb
  12. +2 −0 episode-280/blog-after/app/helpers/comments_helper.rb
  13. +23 −0 episode-280/blog-after/app/helpers/error_messages_helper.rb
  14. +22 −0 episode-280/blog-after/app/helpers/layout_helper.rb
  15. +9 −0 episode-280/blog-after/app/models/article.rb
  16. +4 −0 episode-280/blog-after/app/models/comment.rb
  17. +12 −0 episode-280/blog-after/app/views/articles/_form.html.erb
  18. +8 −0 episode-280/blog-after/app/views/articles/edit.html.erb
  19. +14 −0 episode-280/blog-after/app/views/articles/index.html.erb
  20. +5 −0 episode-280/blog-after/app/views/articles/new.html.erb
  21. +27 −0 episode-280/blog-after/app/views/articles/show.html.erb
  22. +19 −0 episode-280/blog-after/app/views/layouts/application.html.erb
  23. +4 −0 episode-280/blog-after/config.ru
  24. +42 −0 episode-280/blog-after/config/application.rb
  25. +6 −0 episode-280/blog-after/config/boot.rb
  26. +22 −0 episode-280/blog-after/config/database.yml
  27. +5 −0 episode-280/blog-after/config/environment.rb
  28. +25 −0 episode-280/blog-after/config/environments/development.rb
  29. +49 −0 episode-280/blog-after/config/environments/production.rb
  30. +35 −0 episode-280/blog-after/config/environments/test.rb
  31. +7 −0 episode-280/blog-after/config/initializers/backtrace_silencers.rb
  32. +10 −0 episode-280/blog-after/config/initializers/inflections.rb
  33. +5 −0 episode-280/blog-after/config/initializers/mime_types.rb
  34. +7 −0 episode-280/blog-after/config/initializers/secret_token.rb
  35. +8 −0 episode-280/blog-after/config/initializers/session_store.rb
  36. +5 −0 episode-280/blog-after/config/locales/en.yml
  37. +6 −0 episode-280/blog-after/config/routes.rb
  38. +13 −0 episode-280/blog-after/db/migrate/20110627034728_create_articles.rb
  39. +14 −0 episode-280/blog-after/db/migrate/20110808041831_create_comments.rb
  40. +9 −0 episode-280/blog-after/db/migrate/20110808050540_add_published_at_to_articles.rb
  41. +30 −0 episode-280/blog-after/db/schema.rb
  42. +7 −0 episode-280/blog-after/db/seeds.rb
  43. +2 −0 episode-280/blog-after/doc/README_FOR_APP
  44. 0 episode-280/blog-after/lib/tasks/.gitkeep
  45. +26 −0 episode-280/blog-after/public/404.html
  46. +26 −0 episode-280/blog-after/public/422.html
  47. +26 −0 episode-280/blog-after/public/500.html
  48. 0 episode-280/blog-after/public/favicon.ico
  49. BIN episode-280/blog-after/public/images/rails.png
  50. +2 −0 episode-280/blog-after/public/javascripts/application.js
  51. +965 −0 episode-280/blog-after/public/javascripts/controls.js
  52. +974 −0 episode-280/blog-after/public/javascripts/dragdrop.js
  53. +1,123 −0 episode-280/blog-after/public/javascripts/effects.js
  54. +6,001 −0 episode-280/blog-after/public/javascripts/prototype.js
  55. +191 −0 episode-280/blog-after/public/javascripts/rails.js
  56. +5 −0 episode-280/blog-after/public/robots.txt
  57. 0 episode-280/blog-after/public/stylesheets/.gitkeep
  58. +126 −0 episode-280/blog-after/public/stylesheets/application.css
  59. +6 −0 episode-280/blog-after/script/rails
  60. +17 −0 episode-280/blog-after/test/fixtures/articles.yml
  61. +18 −0 episode-280/blog-after/test/fixtures/comments.yml
  62. +54 −0 episode-280/blog-after/test/functional/articles_controller_test.rb
  63. +15 −0 episode-280/blog-after/test/functional/comments_controller_test.rb
  64. +9 −0 episode-280/blog-after/test/performance/browsing_test.rb
  65. +13 −0 episode-280/blog-after/test/test_helper.rb
  66. +7 −0 episode-280/blog-after/test/unit/article_test.rb
  67. +8 −0 episode-280/blog-after/test/unit/comment_test.rb
  68. 0 episode-280/blog-after/vendor/plugins/.gitkeep
  69. +4 −0 episode-280/blog-before/.gitignore
  70. +6 −0 episode-280/blog-before/Gemfile
  71. +78 −0 episode-280/blog-before/Gemfile.lock
  72. +8 −0 episode-280/blog-before/README
  73. +7 −0 episode-280/blog-before/Rakefile
  74. +3 −0 episode-280/blog-before/app/controllers/application_controller.rb
  75. +42 −0 episode-280/blog-before/app/controllers/articles_controller.rb
  76. +7 −0 episode-280/blog-before/app/controllers/comments_controller.rb
  77. +2 −0 episode-280/blog-before/app/helpers/application_helper.rb
  78. +2 −0 episode-280/blog-before/app/helpers/articles_helper.rb
  79. +2 −0 episode-280/blog-before/app/helpers/comments_helper.rb
  80. +23 −0 episode-280/blog-before/app/helpers/error_messages_helper.rb
  81. +22 −0 episode-280/blog-before/app/helpers/layout_helper.rb
  82. +9 −0 episode-280/blog-before/app/models/article.rb
  83. +4 −0 episode-280/blog-before/app/models/comment.rb
  84. +12 −0 episode-280/blog-before/app/views/articles/_form.html.erb
  85. +8 −0 episode-280/blog-before/app/views/articles/edit.html.erb
  86. +14 −0 episode-280/blog-before/app/views/articles/index.html.erb
  87. +5 −0 episode-280/blog-before/app/views/articles/new.html.erb
  88. +27 −0 episode-280/blog-before/app/views/articles/show.html.erb
  89. +19 −0 episode-280/blog-before/app/views/layouts/application.html.erb
  90. +4 −0 episode-280/blog-before/config.ru
  91. +42 −0 episode-280/blog-before/config/application.rb
  92. +6 −0 episode-280/blog-before/config/boot.rb
  93. +22 −0 episode-280/blog-before/config/database.yml
  94. +5 −0 episode-280/blog-before/config/environment.rb
  95. +25 −0 episode-280/blog-before/config/environments/development.rb
  96. +49 −0 episode-280/blog-before/config/environments/production.rb
  97. +35 −0 episode-280/blog-before/config/environments/test.rb
  98. +7 −0 episode-280/blog-before/config/initializers/backtrace_silencers.rb
  99. +10 −0 episode-280/blog-before/config/initializers/inflections.rb
  100. +5 −0 episode-280/blog-before/config/initializers/mime_types.rb
  101. +7 −0 episode-280/blog-before/config/initializers/secret_token.rb
  102. +8 −0 episode-280/blog-before/config/initializers/session_store.rb
  103. +5 −0 episode-280/blog-before/config/locales/en.yml
  104. +6 −0 episode-280/blog-before/config/routes.rb
  105. +13 −0 episode-280/blog-before/db/migrate/20110627034728_create_articles.rb
  106. +14 −0 episode-280/blog-before/db/migrate/20110808041831_create_comments.rb
  107. +9 −0 episode-280/blog-before/db/migrate/20110808050540_add_published_at_to_articles.rb
  108. +30 −0 episode-280/blog-before/db/schema.rb
  109. +7 −0 episode-280/blog-before/db/seeds.rb
  110. +2 −0 episode-280/blog-before/doc/README_FOR_APP
  111. 0 episode-280/blog-before/lib/tasks/.gitkeep
  112. +26 −0 episode-280/blog-before/public/404.html
  113. +26 −0 episode-280/blog-before/public/422.html
  114. +26 −0 episode-280/blog-before/public/500.html
  115. 0 episode-280/blog-before/public/favicon.ico
  116. BIN episode-280/blog-before/public/images/rails.png
  117. +2 −0 episode-280/blog-before/public/javascripts/application.js
  118. +965 −0 episode-280/blog-before/public/javascripts/controls.js
  119. +974 −0 episode-280/blog-before/public/javascripts/dragdrop.js
  120. +1,123 −0 episode-280/blog-before/public/javascripts/effects.js
  121. +6,001 −0 episode-280/blog-before/public/javascripts/prototype.js
  122. +191 −0 episode-280/blog-before/public/javascripts/rails.js
  123. +5 −0 episode-280/blog-before/public/robots.txt
  124. 0 episode-280/blog-before/public/stylesheets/.gitkeep
  125. +126 −0 episode-280/blog-before/public/stylesheets/application.css
  126. +6 −0 episode-280/blog-before/script/rails
  127. +17 −0 episode-280/blog-before/test/fixtures/articles.yml
  128. +18 −0 episode-280/blog-before/test/fixtures/comments.yml
  129. +54 −0 episode-280/blog-before/test/functional/articles_controller_test.rb
  130. +15 −0 episode-280/blog-before/test/functional/comments_controller_test.rb
  131. +9 −0 episode-280/blog-before/test/performance/browsing_test.rb
  132. +13 −0 episode-280/blog-before/test/test_helper.rb
  133. +7 −0 episode-280/blog-before/test/unit/article_test.rb
  134. +8 −0 episode-280/blog-before/test/unit/comment_test.rb
  135. 0 episode-280/blog-before/vendor/plugins/.gitkeep
View
@@ -0,0 +1,10 @@
+RailsCasts Episode #280: Pry with Rails
+
+http://railscasts.com/episodes/280-pry-with-rails
+
+Commands used in episode
+
+ gem install pry pry-doc
+ rvm gemset use global
+ pry
+ pry -r ./config/environment
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
@@ -0,0 +1,6 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.10'
+gem 'sqlite3'
+gem 'nifty-generators'
+gem 'pry', :group => :development
@@ -0,0 +1,91 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.10)
+ actionpack (= 3.0.10)
+ mail (~> 2.2.19)
+ actionpack (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.5.0)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.14)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.10)
+ activesupport (= 3.0.10)
+ builder (~> 2.1.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ arel (~> 2.0.10)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ activesupport (3.0.10)
+ arel (2.0.10)
+ builder (2.1.2)
+ coderay (0.9.8)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ i18n (0.5.0)
+ mail (2.2.19)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ method_source (0.6.0)
+ ruby_parser (>= 2.0.5)
+ mime-types (1.16)
+ nifty-generators (0.4.6)
+ polyglot (0.3.2)
+ pry (0.9.3)
+ coderay (>= 0.9.8)
+ method_source (>= 0.6.0)
+ ruby_parser (>= 2.0.5)
+ slop (~> 1.9.0)
+ rack (1.2.3)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.10)
+ actionmailer (= 3.0.10)
+ actionpack (= 3.0.10)
+ activerecord (= 3.0.10)
+ activeresource (= 3.0.10)
+ activesupport (= 3.0.10)
+ bundler (~> 1.0)
+ railties (= 3.0.10)
+ railties (3.0.10)
+ actionpack (= 3.0.10)
+ activesupport (= 3.0.10)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.4)
+ rake (0.9.2)
+ rdoc (3.9.2)
+ ruby_parser (2.1.0)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.0.6)
+ slop (1.9.1)
+ sqlite3 (1.3.3)
+ thor (0.14.6)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.29)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ nifty-generators
+ pry
+ rails (= 3.0.10)
+ sqlite3
@@ -0,0 +1,8 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:migrate
+ rake db:fixtures:load
+ rails s
@@ -0,0 +1,7 @@
+# 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__)
+require 'rake'
+
+Blog::Application.load_tasks
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,42 @@
+class ArticlesController < ApplicationController
+ def index
+ @articles = Article.all
+ binding.pry
+ end
+
+ def show
+ @article = Article.find(params[:id])
+ end
+
+ def new
+ @article = Article.new
+ end
+
+ def create
+ @article = Article.new(params[:article])
+ if @article.save
+ redirect_to @article, :notice => "Successfully created article."
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @article = Article.find(params[:id])
+ end
+
+ def update
+ @article = Article.find(params[:id])
+ if @article.update_attributes(params[:article])
+ redirect_to @article, :notice => "Successfully updated article."
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @article = Article.find(params[:id])
+ @article.destroy
+ redirect_to articles_url, :notice => "Successfully destroyed article."
+ end
+end
@@ -0,0 +1,7 @@
+class CommentsController < ApplicationController
+ def create
+ @comment = Comment.new(params[:comment])
+ @comment.save!
+ redirect_to @comment.article, :notice => "Successfully created comment."
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
@@ -0,0 +1,23 @@
+module ErrorMessagesHelper
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
+ def error_messages_for(*objects)
+ options = objects.extract_options!
+ options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
+ options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
+ unless messages.empty?
+ content_tag(:div, :class => "error_messages") do
+ list_items = messages.map { |msg| content_tag(:li, msg) }
+ content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
+ end
+ end
+ end
+
+ module FormBuilderAdditions
+ def error_messages(options = {})
+ @template.error_messages_for(@object, options)
+ end
+ end
+end
+
+ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -0,0 +1,22 @@
+# These helper methods can be called in your template to set variables to be used in the layout
+# This module should be included in all views globally,
+# to do so you may need to add this line to your ApplicationController
+# helper :layout
+module LayoutHelper
+ def title(page_title, show_title = true)
+ content_for(:title) { h(page_title.to_s) }
+ @show_title = show_title
+ end
+
+ def show_title?
+ @show_title
+ end
+
+ def stylesheet(*args)
+ content_for(:head) { stylesheet_link_tag(*args) }
+ end
+
+ def javascript(*args)
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+end
@@ -0,0 +1,9 @@
+class Article < ActiveRecord::Base
+ attr_accessible :name, :content, :published_at
+ has_many :comments
+
+ def word_count
+ words = content.scan(/\w+/)
+ words.size
+ end
+end
@@ -0,0 +1,4 @@
+class Comment < ActiveRecord::Base
+ attr_accessible :article_id, :content
+ belongs_to :article
+end
@@ -0,0 +1,12 @@
+<%= form_for @article do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :content %><br />
+ <%= f.text_area :content %>
+ </p>
+ <p><%= f.submit %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Article" %>
+
+<%= render 'form' %>
+
+<p>
+ <%= link_to "Show", @article %> |
+ <%= link_to "View All", articles_path %>
+</p>
@@ -0,0 +1,14 @@
+<% title "Articles" %>
+
+<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="published_at">on <%= article.published_at.strftime('%b %d, %Y') %></div>
+ <div class="content"><%= article.content %></div>
+<% end %>
+</div>
+
+<p><%= link_to "New Article", new_article_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Article" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", articles_path %></p>
@@ -0,0 +1,27 @@
+<% title @article.name %>
+
+<%= @article.content %>
+
+<p>
+ <%= link_to "Edit", edit_article_path(@article) %> |
+ <%= link_to "Destroy", @article, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View All", articles_path %>
+</p>
+
+<h2>Comments</h2>
+
+<div id="comments">
+ <% for comment in @article.comments %>
+ <div class="comment"><%= comment.content %></div>
+ <% end %>
+</div>
+
+<%= form_for @article.comments.build do |f| %>
+ <%= f.error_messages %>
+ <%= f.hidden_field :article_id %>
+ <p>
+ <%= f.label :content, "Comment" %><br />
+ <%= f.text_area :content, :rows => '12', :cols => 35 %>
+ </p>
+ <p><%= f.submit %></p>
+<% end %>
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= content_tag :h1, yield(:title) if show_title? %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
@@ -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
@@ -0,0 +1,42 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+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
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # 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]
+ end
+end
Oops, something went wrong.

0 comments on commit 5a1839c

Please sign in to comment.