Permalink
Browse files

adding revised episode 147

  • Loading branch information...
1 parent a958167 commit 2ba0ecd84c88cb727540813f4eb2243721e2fb6c @ryanb committed Oct 13, 2011
Showing with 1,885 additions and 0 deletions.
  1. +8 −0 episode-147/revised/README
  2. +5 −0 episode-147/revised/faqapp-after/.gitignore
  3. +16 −0 episode-147/revised/faqapp-after/Gemfile
  4. +117 −0 episode-147/revised/faqapp-after/Gemfile.lock
  5. +7 −0 episode-147/revised/faqapp-after/README
  6. +7 −0 episode-147/revised/faqapp-after/Rakefile
  7. BIN episode-147/revised/faqapp-after/app/assets/images/rails.png
  8. +10 −0 episode-147/revised/faqapp-after/app/assets/javascripts/application.js
  9. +9 −0 episode-147/revised/faqapp-after/app/assets/javascripts/faqs.js.coffee
  10. +104 −0 episode-147/revised/faqapp-after/app/assets/stylesheets/application.css
  11. +8 −0 episode-147/revised/faqapp-after/app/assets/stylesheets/faqs.css.scss
  12. +3 −0 episode-147/revised/faqapp-after/app/controllers/application_controller.rb
  13. +48 −0 episode-147/revised/faqapp-after/app/controllers/faqs_controller.rb
  14. +2 −0 episode-147/revised/faqapp-after/app/helpers/application_helper.rb
  15. +2 −0 episode-147/revised/faqapp-after/app/helpers/faqs_helper.rb
  16. 0 episode-147/revised/faqapp-after/app/mailers/.gitkeep
  17. 0 episode-147/revised/faqapp-after/app/models/.gitkeep
  18. +3 −0 episode-147/revised/faqapp-after/app/models/faq.rb
  19. +25 −0 episode-147/revised/faqapp-after/app/views/faqs/_form.html.erb
  20. +6 −0 episode-147/revised/faqapp-after/app/views/faqs/edit.html.erb
  21. +12 −0 episode-147/revised/faqapp-after/app/views/faqs/index.html.erb
  22. +5 −0 episode-147/revised/faqapp-after/app/views/faqs/new.html.erb
  23. +16 −0 episode-147/revised/faqapp-after/app/views/faqs/show.html.erb
  24. +17 −0 episode-147/revised/faqapp-after/app/views/layouts/application.html.erb
  25. +4 −0 episode-147/revised/faqapp-after/config.ru
  26. +48 −0 episode-147/revised/faqapp-after/config/application.rb
  27. +6 −0 episode-147/revised/faqapp-after/config/boot.rb
  28. +25 −0 episode-147/revised/faqapp-after/config/database.yml
  29. +5 −0 episode-147/revised/faqapp-after/config/environment.rb
  30. +30 −0 episode-147/revised/faqapp-after/config/environments/development.rb
  31. +60 −0 episode-147/revised/faqapp-after/config/environments/production.rb
  32. +39 −0 episode-147/revised/faqapp-after/config/environments/test.rb
  33. +7 −0 episode-147/revised/faqapp-after/config/initializers/backtrace_silencers.rb
  34. +10 −0 episode-147/revised/faqapp-after/config/initializers/inflections.rb
  35. +5 −0 episode-147/revised/faqapp-after/config/initializers/mime_types.rb
  36. +7 −0 episode-147/revised/faqapp-after/config/initializers/secret_token.rb
  37. +8 −0 episode-147/revised/faqapp-after/config/initializers/session_store.rb
  38. +14 −0 episode-147/revised/faqapp-after/config/initializers/wrap_parameters.rb
  39. +5 −0 episode-147/revised/faqapp-after/config/locales/en.yml
  40. +6 −0 episode-147/revised/faqapp-after/config/routes.rb
  41. +10 −0 episode-147/revised/faqapp-after/db/migrate/20111013153917_create_faqs.rb
  42. +5 −0 episode-147/revised/faqapp-after/db/migrate/20111013171256_add_position_to_faqs.rb
  43. +24 −0 episode-147/revised/faqapp-after/db/schema.rb
  44. +24 −0 episode-147/revised/faqapp-after/db/seeds.rb
  45. +2 −0 episode-147/revised/faqapp-after/doc/README_FOR_APP
  46. 0 episode-147/revised/faqapp-after/lib/assets/.gitkeep
  47. 0 episode-147/revised/faqapp-after/lib/tasks/.gitkeep
  48. 0 episode-147/revised/faqapp-after/log/.gitkeep
  49. +26 −0 episode-147/revised/faqapp-after/public/404.html
  50. +26 −0 episode-147/revised/faqapp-after/public/422.html
  51. +26 −0 episode-147/revised/faqapp-after/public/500.html
  52. 0 episode-147/revised/faqapp-after/public/favicon.ico
  53. +5 −0 episode-147/revised/faqapp-after/public/robots.txt
  54. +6 −0 episode-147/revised/faqapp-after/script/rails
  55. 0 episode-147/revised/faqapp-after/test/fixtures/.gitkeep
  56. +9 −0 episode-147/revised/faqapp-after/test/fixtures/faqs.yml
  57. 0 episode-147/revised/faqapp-after/test/functional/.gitkeep
  58. +49 −0 episode-147/revised/faqapp-after/test/functional/faqs_controller_test.rb
  59. 0 episode-147/revised/faqapp-after/test/integration/.gitkeep
  60. +12 −0 episode-147/revised/faqapp-after/test/performance/browsing_test.rb
  61. +13 −0 episode-147/revised/faqapp-after/test/test_helper.rb
  62. 0 episode-147/revised/faqapp-after/test/unit/.gitkeep
  63. +7 −0 episode-147/revised/faqapp-after/test/unit/faq_test.rb
  64. +4 −0 episode-147/revised/faqapp-after/test/unit/helpers/faqs_helper_test.rb
  65. 0 episode-147/revised/faqapp-after/vendor/assets/stylesheets/.gitkeep
  66. 0 episode-147/revised/faqapp-after/vendor/plugins/.gitkeep
  67. +5 −0 episode-147/revised/faqapp-before/.gitignore
  68. +15 −0 episode-147/revised/faqapp-before/Gemfile
  69. +119 −0 episode-147/revised/faqapp-before/Gemfile.lock
  70. +7 −0 episode-147/revised/faqapp-before/README
  71. +7 −0 episode-147/revised/faqapp-before/Rakefile
  72. BIN episode-147/revised/faqapp-before/app/assets/images/rails.png
  73. +9 −0 episode-147/revised/faqapp-before/app/assets/javascripts/application.js
  74. +3 −0 episode-147/revised/faqapp-before/app/assets/javascripts/faqs.js.coffee
  75. +104 −0 episode-147/revised/faqapp-before/app/assets/stylesheets/application.css
  76. +3 −0 episode-147/revised/faqapp-before/app/assets/stylesheets/faqs.css.scss
  77. +3 −0 episode-147/revised/faqapp-before/app/controllers/application_controller.rb
  78. +48 −0 episode-147/revised/faqapp-before/app/controllers/faqs_controller.rb
  79. +2 −0 episode-147/revised/faqapp-before/app/helpers/application_helper.rb
  80. +2 −0 episode-147/revised/faqapp-before/app/helpers/faqs_helper.rb
  81. 0 episode-147/revised/faqapp-before/app/mailers/.gitkeep
  82. 0 episode-147/revised/faqapp-before/app/models/.gitkeep
  83. +2 −0 episode-147/revised/faqapp-before/app/models/faq.rb
  84. +25 −0 episode-147/revised/faqapp-before/app/views/faqs/_form.html.erb
  85. +6 −0 episode-147/revised/faqapp-before/app/views/faqs/edit.html.erb
  86. +11 −0 episode-147/revised/faqapp-before/app/views/faqs/index.html.erb
  87. +5 −0 episode-147/revised/faqapp-before/app/views/faqs/new.html.erb
  88. +16 −0 episode-147/revised/faqapp-before/app/views/faqs/show.html.erb
  89. +17 −0 episode-147/revised/faqapp-before/app/views/layouts/application.html.erb
  90. +4 −0 episode-147/revised/faqapp-before/config.ru
  91. +48 −0 episode-147/revised/faqapp-before/config/application.rb
  92. +6 −0 episode-147/revised/faqapp-before/config/boot.rb
  93. +25 −0 episode-147/revised/faqapp-before/config/database.yml
  94. +5 −0 episode-147/revised/faqapp-before/config/environment.rb
  95. +30 −0 episode-147/revised/faqapp-before/config/environments/development.rb
  96. +60 −0 episode-147/revised/faqapp-before/config/environments/production.rb
  97. +39 −0 episode-147/revised/faqapp-before/config/environments/test.rb
  98. +7 −0 episode-147/revised/faqapp-before/config/initializers/backtrace_silencers.rb
  99. +10 −0 episode-147/revised/faqapp-before/config/initializers/inflections.rb
  100. +5 −0 episode-147/revised/faqapp-before/config/initializers/mime_types.rb
  101. +7 −0 episode-147/revised/faqapp-before/config/initializers/secret_token.rb
  102. +8 −0 episode-147/revised/faqapp-before/config/initializers/session_store.rb
  103. +14 −0 episode-147/revised/faqapp-before/config/initializers/wrap_parameters.rb
  104. +5 −0 episode-147/revised/faqapp-before/config/locales/en.yml
  105. +4 −0 episode-147/revised/faqapp-before/config/routes.rb
  106. +10 −0 episode-147/revised/faqapp-before/db/migrate/20111013153917_create_faqs.rb
  107. +23 −0 episode-147/revised/faqapp-before/db/schema.rb
  108. +24 −0 episode-147/revised/faqapp-before/db/seeds.rb
  109. +2 −0 episode-147/revised/faqapp-before/doc/README_FOR_APP
  110. 0 episode-147/revised/faqapp-before/lib/assets/.gitkeep
  111. 0 episode-147/revised/faqapp-before/lib/tasks/.gitkeep
  112. 0 episode-147/revised/faqapp-before/log/.gitkeep
  113. +26 −0 episode-147/revised/faqapp-before/public/404.html
  114. +26 −0 episode-147/revised/faqapp-before/public/422.html
  115. +26 −0 episode-147/revised/faqapp-before/public/500.html
  116. 0 episode-147/revised/faqapp-before/public/favicon.ico
  117. +5 −0 episode-147/revised/faqapp-before/public/robots.txt
  118. +6 −0 episode-147/revised/faqapp-before/script/rails
  119. 0 episode-147/revised/faqapp-before/test/fixtures/.gitkeep
  120. +9 −0 episode-147/revised/faqapp-before/test/fixtures/faqs.yml
  121. 0 episode-147/revised/faqapp-before/test/functional/.gitkeep
  122. +49 −0 episode-147/revised/faqapp-before/test/functional/faqs_controller_test.rb
  123. 0 episode-147/revised/faqapp-before/test/integration/.gitkeep
  124. +12 −0 episode-147/revised/faqapp-before/test/performance/browsing_test.rb
  125. +13 −0 episode-147/revised/faqapp-before/test/test_helper.rb
  126. 0 episode-147/revised/faqapp-before/test/unit/.gitkeep
  127. +7 −0 episode-147/revised/faqapp-before/test/unit/faq_test.rb
  128. +4 −0 episode-147/revised/faqapp-before/test/unit/helpers/faqs_helper_test.rb
  129. 0 episode-147/revised/faqapp-before/vendor/assets/stylesheets/.gitkeep
  130. 0 episode-147/revised/faqapp-before/vendor/plugins/.gitkeep
@@ -0,0 +1,8 @@
+Railscasts Episode #147: Sortable Lists (revised)
+
+http://railscasts.com/episodes/147-sortable-lists-revised
+
+Commands
+
+ rails g migration add_position_to_faqs position:integer
+ rake db:migrate
@@ -0,0 +1,5 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
+.sass-cache/
@@ -0,0 +1,16 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.1.1'
+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'
+
+gem 'acts_as_list'
@@ -0,0 +1,117 @@
+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)
+ acts_as_list (0.1.4)
+ 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.2)
+ erubis (2.7.0)
+ execjs (1.2.9)
+ multi_json (~> 1.0)
+ hike (1.2.1)
+ i18n (0.6.0)
+ jquery-rails (1.0.16)
+ 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.16)
+ multi_json (1.0.3)
+ polyglot (0.3.2)
+ rack (1.3.3)
+ 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)
+ rdoc (3.10)
+ json (~> 1.4)
+ sass (3.1.10)
+ sass-rails (3.1.4)
+ actionpack (~> 3.1.0)
+ railties (~> 3.1.0)
+ sass (>= 3.1.4)
+ sprockets (~> 2.0.0)
+ tilt (~> 1.3.2)
+ sprockets (2.0.2)
+ 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.30)
+ uglifier (1.0.3)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ acts_as_list
+ coffee-rails (~> 3.1.1)
+ jquery-rails
+ rails (= 3.1.1)
+ sass-rails (~> 3.1.4)
+ sqlite3
+ uglifier (>= 1.0.3)
@@ -0,0 +1,7 @@
+= RailsCasts Example Application
+
+Run these commands to try it out.
+
+ bundle
+ rake db:setup
+ rails s
@@ -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__)
+
+Faqapp::Application.load_tasks
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,10 @@
+// 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-ui
+//= require jquery_ujs
+//= require_tree .
@@ -0,0 +1,9 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
+jQuery ->
+ $('#faqs').sortable
+ axis: 'y'
+ handle: '.handle'
+ update: ->
+ $.post($(this).data('update-url'), $(this).sortable('serialize'))
@@ -0,0 +1,104 @@
+/*
+ * 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 .
+*/
+
+html, body {
+ background-color: #4B7399;
+ font-family: Verdana, Helvetica, Arial;
+ font-size: 14px;
+}
+
+a img {
+ border: none;
+}
+
+a {
+ color: #0000FF;
+ text-decoration: none;
+}
+
+a:hover {
+ text-decoration: underline;
+}
+
+.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;
+}
+
+form label {
+ display: block;
+ margin-bottom: 2px;
+}
+
+form .field, form .actions {
+ margin: 12px 0;
+}
+
+.fieldWithErrors {
+ display: inline;
+}
+
+.error_messages {
+ width: 400px;
+ border: 2px solid #CF0000;
+ padding: 0px;
+ 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: 15px 0;
+}
+
+ul {
+ padding-left: 20px;
+}
+
+ul li {
+ margin: 5px 0;
+}
@@ -0,0 +1,8 @@
+// Place all the styles related to the faqs controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
+#faqs .handle {
+ font-size: 12px;
+ color: #777;
+ cursor: move;
+}
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,48 @@
+class FaqsController < ApplicationController
+ def index
+ @faqs = Faq.order("position")
+ end
+
+ def show
+ @faq = Faq.find(params[:id])
+ end
+
+ def new
+ @faq = Faq.new
+ end
+
+ def create
+ @faq = Faq.new(params[:faq])
+ if @faq.save
+ redirect_to @faq, notice: "Successfully created FAQ."
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @faq = Faq.find(params[:id])
+ end
+
+ def update
+ @faq = Faq.find(params[:id])
+ if @faq.update_attributes(params[:faq])
+ redirect_to @faq, notice: "Successfully updated FAQ."
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @faq = Faq.find(params[:id])
+ @faq.destroy
+ redirect_to faqs_url, notice: "Successfully destroyed FAQ."
+ end
+
+ def sort
+ params[:faq].each_with_index do |id, index|
+ Faq.update_all({position: index+1}, {id: id})
+ end
+ render nothing: true
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,2 @@
+module FaqsHelper
+end
@@ -0,0 +1,3 @@
+class Faq < ActiveRecord::Base
+ acts_as_list
+end
@@ -0,0 +1,25 @@
+<%= form_for(@faq) do |f| %>
+ <% if @faq.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@faq.errors.count, "error") %> prohibited this faq from being saved:</h2>
+
+ <ul>
+ <% @faq.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :question %><br />
+ <%= f.text_area :question %>
+ </div>
+ <div class="field">
+ <%= f.label :answer %><br />
+ <%= f.text_area :answer %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing faq</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @faq %> |
+<%= link_to 'Back', faqs_path %>
Oops, something went wrong.

0 comments on commit 2ba0ecd

Please sign in to comment.