Permalink
Browse files

adding episode 149

  • Loading branch information...
1 parent e35b47d commit 78c872eeec81d89d6ee044166d5f354634cdab16 @ryanb committed Feb 16, 2009
Showing with 17,404 additions and 0 deletions.
  1. +17 −0 episode-149/README
  2. +3 −0 episode-149/blog/.gitignore
  3. +4 −0 episode-149/blog/README
  4. +10 −0 episode-149/blog/Rakefile
  5. +15 −0 episode-149/blog/app/controllers/application_controller.rb
  6. +45 −0 episode-149/blog/app/controllers/articles_controller.rb
  7. +36 −0 episode-149/blog/app/controllers/comments_controller.rb
  8. +3 −0 episode-149/blog/app/helpers/application_helper.rb
  9. +2 −0 episode-149/blog/app/helpers/articles_helper.rb
  10. +2 −0 episode-149/blog/app/helpers/comments_helper.rb
  11. +23 −0 episode-149/blog/app/helpers/layout_helper.rb
  12. +4 −0 episode-149/blog/app/models/article.rb
  13. +4 −0 episode-149/blog/app/models/comment.rb
  14. +16 −0 episode-149/blog/app/views/articles/_form.html.erb
  15. +8 −0 episode-149/blog/app/views/articles/edit.html.erb
  16. +13 −0 episode-149/blog/app/views/articles/index.html.erb
  17. +5 −0 episode-149/blog/app/views/articles/new.html.erb
  18. +24 −0 episode-149/blog/app/views/articles/show.html.erb
  19. +17 −0 episode-149/blog/app/views/comments/_form.html.erb
  20. +4 −0 episode-149/blog/app/views/comments/edit.html.erb
  21. +4 −0 episode-149/blog/app/views/comments/new.html.erb
  22. +22 −0 episode-149/blog/app/views/layouts/application.html.erb
  23. +109 −0 episode-149/blog/config/boot.rb
  24. +19 −0 episode-149/blog/config/database.yml
  25. +67 −0 episode-149/blog/config/environment.rb
  26. +17 −0 episode-149/blog/config/environments/development.rb
  27. +22 −0 episode-149/blog/config/environments/production.rb
  28. +22 −0 episode-149/blog/config/environments/test.rb
  29. +10 −0 episode-149/blog/config/initializers/inflections.rb
  30. +5 −0 episode-149/blog/config/initializers/mime_types.rb
  31. +15 −0 episode-149/blog/config/initializers/new_rails_defaults.rb
  32. +4 −0 episode-149/blog/config/routes.rb
  33. +14 −0 episode-149/blog/db/migrate/20080719200447_create_articles.rb
  34. +15 −0 episode-149/blog/db/migrate/20080719201435_create_comments.rb
  35. +31 −0 episode-149/blog/db/schema.rb
  36. +2 −0 episode-149/blog/doc/README_FOR_APP
  37. +2 −0 episode-149/blog/lib/tasks/application.rake
  38. +30 −0 episode-149/blog/public/404.html
  39. +30 −0 episode-149/blog/public/422.html
  40. +30 −0 episode-149/blog/public/500.html
  41. +10 −0 episode-149/blog/public/dispatch.cgi
  42. +24 −0 episode-149/blog/public/dispatch.fcgi
  43. +10 −0 episode-149/blog/public/dispatch.rb
  44. 0 episode-149/blog/public/favicon.ico
  45. +2 −0 episode-149/blog/public/javascripts/application.js
  46. +963 −0 episode-149/blog/public/javascripts/controls.js
  47. +973 −0 episode-149/blog/public/javascripts/dragdrop.js
  48. +1,128 −0 episode-149/blog/public/javascripts/effects.js
  49. +4,320 −0 episode-149/blog/public/javascripts/prototype.js
  50. +5 −0 episode-149/blog/public/robots.txt
  51. +113 −0 episode-149/blog/public/stylesheets/application.css
  52. +3 −0 episode-149/blog/script/about
  53. +3 −0 episode-149/blog/script/console
  54. +3 −0 episode-149/blog/script/dbconsole
  55. +3 −0 episode-149/blog/script/destroy
  56. +3 −0 episode-149/blog/script/generate
  57. +3 −0 episode-149/blog/script/performance/benchmarker
  58. +3 −0 episode-149/blog/script/performance/profiler
  59. +3 −0 episode-149/blog/script/performance/request
  60. +3 −0 episode-149/blog/script/plugin
  61. +3 −0 episode-149/blog/script/process/inspector
  62. +3 −0 episode-149/blog/script/process/reaper
  63. +3 −0 episode-149/blog/script/process/spawner
  64. +3 −0 episode-149/blog/script/runner
  65. +3 −0 episode-149/blog/script/server
  66. +17 −0 episode-149/blog/test/fixtures/articles.yml
  67. +21 −0 episode-149/blog/test/fixtures/comments.yml
  68. +54 −0 episode-149/blog/test/functional/articles_controller_test.rb
  69. +44 −0 episode-149/blog/test/functional/comments_controller_test.rb
  70. +38 −0 episode-149/blog/test/test_helper.rb
  71. +8 −0 episode-149/blog/test/unit/article_test.rb
  72. +8 −0 episode-149/blog/test/unit/comment_test.rb
  73. +3 −0 episode-149/store/.gitignore
  74. +4 −0 episode-149/store/README
  75. +10 −0 episode-149/store/Rakefile
  76. +15 −0 episode-149/store/app/controllers/application_controller.rb
  77. +44 −0 episode-149/store/app/controllers/categories_controller.rb
  78. +44 −0 episode-149/store/app/controllers/products_controller.rb
  79. +3 −0 episode-149/store/app/helpers/application_helper.rb
  80. +2 −0 episode-149/store/app/helpers/categories_helper.rb
  81. +23 −0 episode-149/store/app/helpers/layout_helper.rb
  82. +2 −0 episode-149/store/app/helpers/products_helper.rb
  83. +3 −0 episode-149/store/app/models/category.rb
  84. +3 −0 episode-149/store/app/models/product.rb
  85. +7 −0 episode-149/store/app/views/categories/_form.html.erb
  86. +8 −0 episode-149/store/app/views/categories/edit.html.erb
  87. +13 −0 episode-149/store/app/views/categories/index.html.erb
  88. +5 −0 episode-149/store/app/views/categories/new.html.erb
  89. +13 −0 episode-149/store/app/views/categories/show.html.erb
  90. +22 −0 episode-149/store/app/views/layouts/application.html.erb
  91. +19 −0 episode-149/store/app/views/products/_form.html.erb
  92. +8 −0 episode-149/store/app/views/products/edit.html.erb
  93. +16 −0 episode-149/store/app/views/products/index.html.erb
  94. +5 −0 episode-149/store/app/views/products/new.html.erb
  95. +21 −0 episode-149/store/app/views/products/show.html.erb
  96. +109 −0 episode-149/store/config/boot.rb
  97. +19 −0 episode-149/store/config/database.yml
  98. +67 −0 episode-149/store/config/environment.rb
  99. +17 −0 episode-149/store/config/environments/development.rb
  100. +22 −0 episode-149/store/config/environments/production.rb
  101. +22 −0 episode-149/store/config/environments/test.rb
  102. +10 −0 episode-149/store/config/initializers/inflections.rb
  103. +5 −0 episode-149/store/config/initializers/mime_types.rb
  104. +15 −0 episode-149/store/config/initializers/new_rails_defaults.rb
  105. +5 −0 episode-149/store/config/routes.rb
  106. +12 −0 episode-149/store/db/migrate/20080621194238_create_categories.rb
  107. +15 −0 episode-149/store/db/migrate/20080621194423_create_products.rb
  108. +14 −0 episode-149/store/db/migrate/20080719200447_create_articles.rb
  109. +15 −0 episode-149/store/db/migrate/20080719201435_create_comments.rb
  110. +46 −0 episode-149/store/db/schema.rb
  111. +23 −0 episode-149/store/lib/tasks/application.rake
  112. +30 −0 episode-149/store/public/404.html
  113. +30 −0 episode-149/store/public/422.html
  114. +30 −0 episode-149/store/public/500.html
  115. +10 −0 episode-149/store/public/dispatch.cgi
  116. +24 −0 episode-149/store/public/dispatch.fcgi
  117. +10 −0 episode-149/store/public/dispatch.rb
  118. 0 episode-149/store/public/favicon.ico
  119. +2 −0 episode-149/store/public/javascripts/application.js
  120. +963 −0 episode-149/store/public/javascripts/controls.js
  121. +973 −0 episode-149/store/public/javascripts/dragdrop.js
  122. +1,128 −0 episode-149/store/public/javascripts/effects.js
  123. +4,320 −0 episode-149/store/public/javascripts/prototype.js
  124. +5 −0 episode-149/store/public/robots.txt
  125. +88 −0 episode-149/store/public/stylesheets/application.css
  126. +3 −0 episode-149/store/script/about
  127. +3 −0 episode-149/store/script/console
  128. +3 −0 episode-149/store/script/dbconsole
  129. +3 −0 episode-149/store/script/destroy
  130. +3 −0 episode-149/store/script/generate
  131. +3 −0 episode-149/store/script/performance/benchmarker
  132. +3 −0 episode-149/store/script/performance/profiler
  133. +3 −0 episode-149/store/script/performance/request
  134. +3 −0 episode-149/store/script/plugin
  135. +3 −0 episode-149/store/script/process/inspector
  136. +3 −0 episode-149/store/script/process/reaper
  137. +3 −0 episode-149/store/script/process/spawner
  138. +3 −0 episode-149/store/script/runner
  139. +3 −0 episode-149/store/script/server
  140. +5 −0 episode-149/store/test/fixtures/categories.yml
  141. +11 −0 episode-149/store/test/fixtures/products.yml
  142. +54 −0 episode-149/store/test/functional/categories_controller_test.rb
  143. +54 −0 episode-149/store/test/functional/products_controller_test.rb
  144. +38 −0 episode-149/store/test/test_helper.rb
  145. +8 −0 episode-149/store/test/unit/category_test.rb
  146. +8 −0 episode-149/store/test/unit/product_test.rb
  147. 0 episode-149/store/vendor/plugins/.gitignore
  148. +20 −0 episode-149/store/vendor/plugins/blogify/MIT-LICENSE
  149. +13 −0 episode-149/store/vendor/plugins/blogify/README
  150. +23 −0 episode-149/store/vendor/plugins/blogify/Rakefile
  151. +15 −0 episode-149/store/vendor/plugins/blogify/app/controllers/application_controller.rb
  152. +45 −0 episode-149/store/vendor/plugins/blogify/app/controllers/articles_controller.rb
  153. +36 −0 episode-149/store/vendor/plugins/blogify/app/controllers/comments_controller.rb
  154. +3 −0 episode-149/store/vendor/plugins/blogify/app/helpers/application_helper.rb
  155. +2 −0 episode-149/store/vendor/plugins/blogify/app/helpers/articles_helper.rb
  156. +2 −0 episode-149/store/vendor/plugins/blogify/app/helpers/comments_helper.rb
  157. +23 −0 episode-149/store/vendor/plugins/blogify/app/helpers/layout_helper.rb
  158. +4 −0 episode-149/store/vendor/plugins/blogify/app/models/article.rb
  159. +4 −0 episode-149/store/vendor/plugins/blogify/app/models/comment.rb
  160. +16 −0 episode-149/store/vendor/plugins/blogify/app/views/articles/_form.html.erb
  161. +8 −0 episode-149/store/vendor/plugins/blogify/app/views/articles/edit.html.erb
  162. +13 −0 episode-149/store/vendor/plugins/blogify/app/views/articles/index.html.erb
  163. +5 −0 episode-149/store/vendor/plugins/blogify/app/views/articles/new.html.erb
  164. +24 −0 episode-149/store/vendor/plugins/blogify/app/views/articles/show.html.erb
  165. +17 −0 episode-149/store/vendor/plugins/blogify/app/views/comments/_form.html.erb
  166. +4 −0 episode-149/store/vendor/plugins/blogify/app/views/comments/edit.html.erb
  167. +4 −0 episode-149/store/vendor/plugins/blogify/app/views/comments/new.html.erb
  168. +22 −0 episode-149/store/vendor/plugins/blogify/app/views/layouts/application.html.erb
  169. +3 −0 episode-149/store/vendor/plugins/blogify/config/routes.rb
  170. +14 −0 episode-149/store/vendor/plugins/blogify/db/migrate/20080719200447_create_articles.rb
  171. +15 −0 episode-149/store/vendor/plugins/blogify/db/migrate/20080719201435_create_comments.rb
  172. +1 −0 episode-149/store/vendor/plugins/blogify/init.rb
  173. +1 −0 episode-149/store/vendor/plugins/blogify/install.rb
  174. +1 −0 episode-149/store/vendor/plugins/blogify/lib/blogify.rb
  175. +7 −0 episode-149/store/vendor/plugins/blogify/tasks/blogify_tasks.rake
  176. +8 −0 episode-149/store/vendor/plugins/blogify/test/blogify_test.rb
  177. +3 −0 episode-149/store/vendor/plugins/blogify/test/test_helper.rb
  178. +1 −0 episode-149/store/vendor/plugins/blogify/uninstall.rb
View
@@ -0,0 +1,17 @@
+Railscasts Episode #149: Rails Engines
+
+http://railscasts.com/episodes/149
+
+Commands
+
+ gem install rails --source http://gems.rubyonrails.org
+ rails -v
+ script/generate plugin blogify
+ cd vendor/plugins/blogify
+ cp -R ~/code/blog/app .
+ mkdir config
+ cp ~/code/blog/config/routes.rb config
+ mkdir db
+ cp -R ~/code/blog/db/migrate db
+ rake db:migrate
+ rake blogify:sync
@@ -0,0 +1,3 @@
+tmp/*
+log/*
+*.sqlite3
@@ -0,0 +1,4 @@
+Railscasts Example Blog App
+--
+
+To setup the app, just run `rake setup`.
@@ -0,0 +1,10 @@
+# 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.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
@@ -0,0 +1,15 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+
+ # See ActionController::RequestForgeryProtection for details
+ # Uncomment the :secret if you're not using the cookie session store
+ protect_from_forgery # :secret => '9346baedc099926e71cc3a3f39613aa6'
+
+ # See ActionController::Base for details
+ # Uncomment this to filter the contents of submitted sensitive data parameters
+ # from your application log (in this case, all fields with names like "password").
+ # filter_parameter_logging :password
+end
@@ -0,0 +1,45 @@
+class ArticlesController < ApplicationController
+ def index
+ @articles = Article.find(:all)
+ end
+
+ def show
+ @article = Article.find(params[:id])
+ @comment = Comment.new(:article => @article)
+ end
+
+ def new
+ @article = Article.new
+ end
+
+ def create
+ @article = Article.new(params[:article])
+ if @article.save
+ flash[:notice] = "Successfully created article."
+ redirect_to @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])
+ flash[:notice] = "Successfully updated article."
+ redirect_to @article
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @article = Article.find(params[:id])
+ @article.destroy
+ flash[:notice] = "Successfully destroyed article."
+ redirect_to articles_url
+ end
+end
@@ -0,0 +1,36 @@
+class CommentsController < ApplicationController
+ def new
+ @comment = Comment.new
+ end
+
+ def create
+ @comment = Comment.new(params[:comment])
+ if @comment.save
+ flash[:notice] = "Successfully created comment."
+ redirect_to article_url(@comment.article_id)
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @comment = Comment.find(params[:id])
+ end
+
+ def update
+ @comment = Comment.find(params[:id])
+ if @comment.update_attributes(params[:comment])
+ flash[:notice] = "Successfully updated comment."
+ redirect_to article_url(@comment.article_id)
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @comment = Comment.find(params[:id])
+ @comment.destroy
+ flash[:notice] = "Successfully destroyed comment."
+ redirect_to article_url(@comment.article_id)
+ end
+end
@@ -0,0 +1,3 @@
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+end
@@ -0,0 +1,2 @@
+module ArticlesHelper
+end
@@ -0,0 +1,2 @@
+module CommentsHelper
+end
@@ -0,0 +1,23 @@
+# 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 = 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.map(&:to_s)) }
+ end
+
+ def javascript(*args)
+ args = args.map { |arg| arg == :defaults ? arg : arg.to_s }
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+end
@@ -0,0 +1,4 @@
+class Article < ActiveRecord::Base
+ has_many :comments, :dependent => :destroy
+ validates_presence_of :name, :content
+end
@@ -0,0 +1,4 @@
+class Comment < ActiveRecord::Base
+ belongs_to :article
+ validates_presence_of :author_name, :content
+end
@@ -0,0 +1,16 @@
+<%= error_messages_for :article %>
+<% form_for @article do |f| %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :content %><br />
+ <%= f.text_area :content %>
+ </p>
+ <p>
+ <%= f.label :author_name %><br />
+ <%= f.text_field :author_name %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Article" %>
+
+<%= render :partial => 'form' %>
+
+<p>
+ <%= link_to "Show", @article %> |
+ <%= link_to "View All", articles_path %>
+</p>
@@ -0,0 +1,13 @@
+<% title "Articles" %>
+
+<div id="articles">
+<% for article in @articles %>
+ <h2>
+ <%= link_to h(article.name), article %>
+ <span class="comments">(<%= pluralize(article.comments.size, 'comment') %>)</span>
+ </h2>
+ <div class="author">from <%=h article.author_name %> on <%= article.created_at.strftime('%b %d, %Y') %></div>
+ <div class="content"><%= simple_format(article.content) %></div>
+<% end %>
+</div>
+<p><%= link_to "New Article", new_article_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Article" %>
+
+<%= render :partial => 'form' %>
+
+<p><%= link_to "Back to List", articles_path %></p>
@@ -0,0 +1,24 @@
+<% title @article.name %>
+
+<p class="author"><em>from <%=h @article.author_name %></em></p>
+
+<%=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.site_url.blank?, h(comment.author_name), h(comment.site_url) %></strong>
+ <em>on <%= comment.created_at.strftime('%b %d, %Y at %H:%M') %></em>
+ <%=simple_format comment.content %>
+ </div>
+ <% end %>
+ </div>
+<% end %>
+
+<h3>Add your comment:</h3>
+<%= render :partial => 'comments/form' %>
@@ -0,0 +1,17 @@
+<%= error_messages_for :comment %>
+<% form_for @comment do |f| %>
+ <%= f.hidden_field :article_id %>
+ <p>
+ <%= f.label :author_name, 'Name' %><br />
+ <%= f.text_field :author_name %>
+ </p>
+ <p>
+ <%= f.label :site_url, 'Website URL' %><br />
+ <%= f.text_field :site_url %>
+ </p>
+ <p>
+ <%= f.label :content, 'Comment' %><br />
+ <%= f.text_area :content, :rows => '12', :cols => 35 %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
@@ -0,0 +1,4 @@
+<% title "Edit Comment" %>
+
+<%= render :partial => 'form' %>
+
@@ -0,0 +1,4 @@
+<% title "New Comment" %>
+
+<%= render :partial => 'form' %>
+
@@ -0,0 +1,22 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title><%= h(yield(:title) || "Untitled") %></title>
+ <%= stylesheet_link_tag 'application' %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <%- flash.each do |name, msg| -%>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <%- end -%>
+
+ <%- if show_title? -%>
+ <h1><%=h yield(:title) %></h1>
+ <%- end -%>
+
+ <%= yield %>
+ </div>
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit 78c872e

Please sign in to comment.