Permalink
Browse files

adding episode 136

  • Loading branch information...
1 parent 353ad5a commit 4d8e822c571542bb0b231be4b35570d27aa78f75 @ryanb committed Nov 16, 2008
Showing with 8,546 additions and 0 deletions.
  1. +3 −0 episode-136/README
  2. +3 −0 episode-136/store/.gitignore
  3. +4 −0 episode-136/store/README
  4. +10 −0 episode-136/store/Rakefile
  5. +15 −0 episode-136/store/app/controllers/application.rb
  6. +44 −0 episode-136/store/app/controllers/categories_controller.rb
  7. +44 −0 episode-136/store/app/controllers/products_controller.rb
  8. +10 −0 episode-136/store/app/controllers/reviews_controller.rb
  9. +3 −0 episode-136/store/app/helpers/application_helper.rb
  10. +2 −0 episode-136/store/app/helpers/categories_helper.rb
  11. +23 −0 episode-136/store/app/helpers/layout_helper.rb
  12. +2 −0 episode-136/store/app/helpers/products_helper.rb
  13. +2 −0 episode-136/store/app/helpers/reviews_helper.rb
  14. +3 −0 episode-136/store/app/models/category.rb
  15. +4 −0 episode-136/store/app/models/product.rb
  16. +3 −0 episode-136/store/app/models/review.rb
  17. +7 −0 episode-136/store/app/views/categories/_form.html.erb
  18. +8 −0 episode-136/store/app/views/categories/edit.html.erb
  19. +13 −0 episode-136/store/app/views/categories/index.html.erb
  20. +5 −0 episode-136/store/app/views/categories/new.html.erb
  21. +13 −0 episode-136/store/app/views/categories/show.html.erb
  22. +23 −0 episode-136/store/app/views/layouts/application.html.erb
  23. +19 −0 episode-136/store/app/views/products/_form.html.erb
  24. +8 −0 episode-136/store/app/views/products/edit.html.erb
  25. +16 −0 episode-136/store/app/views/products/index.html.erb
  26. +5 −0 episode-136/store/app/views/products/new.html.erb
  27. +26 −0 episode-136/store/app/views/products/show.html.erb
  28. +4 −0 episode-136/store/app/views/reviews/_review.html.erb
  29. +4 −0 episode-136/store/app/views/reviews/create.js.erb
  30. +109 −0 episode-136/store/config/boot.rb
  31. +19 −0 episode-136/store/config/database.yml
  32. +67 −0 episode-136/store/config/environment.rb
  33. +17 −0 episode-136/store/config/environments/development.rb
  34. +22 −0 episode-136/store/config/environments/production.rb
  35. +22 −0 episode-136/store/config/environments/test.rb
  36. +10 −0 episode-136/store/config/initializers/inflections.rb
  37. +5 −0 episode-136/store/config/initializers/mime_types.rb
  38. +15 −0 episode-136/store/config/initializers/new_rails_defaults.rb
  39. +7 −0 episode-136/store/config/routes.rb
  40. +12 −0 episode-136/store/db/migrate/20080621194238_create_categories.rb
  41. +15 −0 episode-136/store/db/migrate/20080621194423_create_products.rb
  42. +14 −0 episode-136/store/db/migrate/20081115171229_create_reviews.rb
  43. +37 −0 episode-136/store/db/schema.rb
  44. +23 −0 episode-136/store/lib/tasks/application.rake
  45. +30 −0 episode-136/store/public/404.html
  46. +30 −0 episode-136/store/public/422.html
  47. +30 −0 episode-136/store/public/500.html
  48. +10 −0 episode-136/store/public/dispatch.cgi
  49. +24 −0 episode-136/store/public/dispatch.fcgi
  50. +10 −0 episode-136/store/public/dispatch.rb
  51. 0 episode-136/store/public/favicon.ico
  52. +17 −0 episode-136/store/public/javascripts/application.js
  53. +963 −0 episode-136/store/public/javascripts/controls.js
  54. +972 −0 episode-136/store/public/javascripts/dragdrop.js
  55. +1,120 −0 episode-136/store/public/javascripts/effects.js
  56. +32 −0 episode-136/store/public/javascripts/jquery.js
  57. +4,225 −0 episode-136/store/public/javascripts/prototype.js
  58. +5 −0 episode-136/store/public/robots.txt
  59. +107 −0 episode-136/store/public/stylesheets/application.css
  60. +3 −0 episode-136/store/script/about
  61. +3 −0 episode-136/store/script/console
  62. +3 −0 episode-136/store/script/dbconsole
  63. +3 −0 episode-136/store/script/destroy
  64. +3 −0 episode-136/store/script/generate
  65. +3 −0 episode-136/store/script/performance/benchmarker
  66. +3 −0 episode-136/store/script/performance/profiler
  67. +3 −0 episode-136/store/script/performance/request
  68. +3 −0 episode-136/store/script/plugin
  69. +3 −0 episode-136/store/script/process/inspector
  70. +3 −0 episode-136/store/script/process/reaper
  71. +3 −0 episode-136/store/script/process/spawner
  72. +3 −0 episode-136/store/script/runner
  73. +3 −0 episode-136/store/script/server
  74. +5 −0 episode-136/store/test/fixtures/categories.yml
  75. +11 −0 episode-136/store/test/fixtures/products.yml
  76. +9 −0 episode-136/store/test/fixtures/reviews.yml
  77. +54 −0 episode-136/store/test/functional/categories_controller_test.rb
  78. +54 −0 episode-136/store/test/functional/products_controller_test.rb
  79. +15 −0 episode-136/store/test/functional/reviews_controller_test.rb
  80. +38 −0 episode-136/store/test/test_helper.rb
  81. +8 −0 episode-136/store/test/unit/category_test.rb
  82. +8 −0 episode-136/store/test/unit/product_test.rb
  83. +7 −0 episode-136/store/test/unit/review_test.rb
  84. 0 episode-136/store/vendor/plugins/.gitignore
View
@@ -0,0 +1,3 @@
+Railscasts Episode #136: jQuery
+
+http://railscasts.com/episodes/136
@@ -0,0 +1,3 @@
+tmp/*
+log/*
+*.sqlite3
View
@@ -0,0 +1,4 @@
+Railscasts Example Store App
+--
+
+To setup the app, just run `rake setup`.
View
@@ -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 => '526292d4095d0fd8135a9aa118f5956e'
+
+ # 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,44 @@
+class CategoriesController < ApplicationController
+ def index
+ @categories = Category.find(:all)
+ end
+
+ def show
+ @category = Category.find(params[:id])
+ end
+
+ def new
+ @category = Category.new
+ end
+
+ def create
+ @category = Category.new(params[:category])
+ if @category.save
+ flash[:notice] = "Successfully created category."
+ redirect_to @category
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @category = Category.find(params[:id])
+ end
+
+ def update
+ @category = Category.find(params[:id])
+ if @category.update_attributes(params[:category])
+ flash[:notice] = "Successfully updated category."
+ redirect_to @category
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @category = Category.find(params[:id])
+ @category.destroy
+ flash[:notice] = "Successfully destroyed category."
+ redirect_to categories_url
+ end
+end
@@ -0,0 +1,44 @@
+class ProductsController < ApplicationController
+ def index
+ @products = Product.all(:limit => 10)
+ end
+
+ def show
+ @product = Product.find(params[:id])
+ end
+
+ def new
+ @product = Product.new
+ end
+
+ def create
+ @product = Product.new(params[:product])
+ if @product.save
+ flash[:notice] = "Successfully created product."
+ redirect_to @product
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @product = Product.find(params[:id])
+ end
+
+ def update
+ @product = Product.find(params[:id])
+ if @product.update_attributes(params[:product])
+ flash[:notice] = "Successfully updated product."
+ redirect_to @product
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @product = Product.find(params[:id])
+ @product.destroy
+ flash[:notice] = "Successfully destroyed product."
+ redirect_to products_url
+ end
+end
@@ -0,0 +1,10 @@
+class ReviewsController < ApplicationController
+ def create
+ @review = Review.create!(params[:review])
+ flash[:notice] = "Thank you for reviewing this product"
+ respond_to do |format|
+ format.html { redirect_to @review.product }
+ format.js
+ end
+ 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 CategoriesHelper
+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,2 @@
+module ProductsHelper
+end
@@ -0,0 +1,2 @@
+module ReviewsHelper
+end
@@ -0,0 +1,3 @@
+class Category < ActiveRecord::Base
+ has_many :products
+end
@@ -0,0 +1,4 @@
+class Product < ActiveRecord::Base
+ belongs_to :category
+ has_many :reviews
+end
@@ -0,0 +1,3 @@
+class Review < ActiveRecord::Base
+ belongs_to :product
+end
@@ -0,0 +1,7 @@
+<% form_for @category do |f| %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Category" %>
+
+<%= render :partial => 'form' %>
+
+<p>
+ <%= link_to "Show", @category %> |
+ <%= link_to "View All", categories_path %>
+</p>
@@ -0,0 +1,13 @@
+<% title "Categories" %>
+
+<% for category in @categories %>
+ <div class="category">
+ <h3><%= link_to h(category.name), category %></h3>
+ <div class="actions">
+ <%= link_to "Edit", edit_category_path(category) %> |
+ <%= link_to "Destroy", category, :confirm => 'Are you sure?', :method => :delete %>
+ </div>
+ </div>
+<% end %>
+
+<p><%= link_to "New Category", new_category_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Category" %>
+
+<%= render :partial => 'form' %>
+
+<p><%= link_to "Back to List", categories_path %></p>
@@ -0,0 +1,13 @@
+<% title @category.name %>
+
+<ul>
+<% for product in @category.products %>
+ <li><%= link_to h(product.name), product %></li>
+<% end %>
+</ul>
+
+<p>
+ <%= link_to "Edit", edit_category_path(@category) %> |
+ <%= link_to "Destroy", @category, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View All", categories_path %>
+</p>
@@ -0,0 +1,23 @@
+<!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' %>
+ <%= javascript_include_tag 'jquery', '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>
@@ -0,0 +1,19 @@
+<% form_for @product do |f| %>
+ <p>
+ <%= f.label :category_id %><br />
+ <%= f.collection_select :category_id, Category.all, :id, :name %>
+ </p>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :price %><br />
+ <%= f.text_field :price %>
+ </p>
+ <p>
+ <%= f.label :description %><br />
+ <%= f.text_area :description %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Product" %>
+
+<%= render :partial => 'form' %>
+
+<p>
+ <%= link_to "Show", @product %> |
+ <%= link_to "View All", products_path %>
+</p>
@@ -0,0 +1,16 @@
+<% title "Products" %>
+
+<% for product in @products %>
+ <div class="product">
+ <h3>
+ <%= link_to h(product.name), product %>
+ <%= number_to_currency(product.price) %>
+ </h3>
+ <div class="actions">
+ <%= link_to "Edit", edit_product_path(product) %> |
+ <%= link_to "Destroy", product, :confirm => 'Are you sure?', :method => :delete %>
+ </div>
+ </div>
+<% end %>
+
+<p><%= link_to "New Product", new_product_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Product" %>
+
+<%= render :partial => 'form' %>
+
+<p><%= link_to "Back to List", products_path %></p>
@@ -0,0 +1,26 @@
+<% title @product.name %>
+
+<p>
+ Price: <%= number_to_currency @product.price %>
+</p>
+
+<h3 id="reviews_count"><%= pluralize(@product.reviews.size, "Review") %></h3>
+
+<div id="reviews">
+ <%= render :partial => @product.reviews %>
+</div>
+
+<h3>Add a Review</h3>
+
+<% form_for Review.new(:product => @product) do |f| %>
+ <%= f.hidden_field :product_id %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :content, "Review" %><br />
+ <%= f.text_area :content, :rows => 8 %>
+ </p>
+ <p><%= f.submit "Add Review" %></p>
+<% end %>
@@ -0,0 +1,4 @@
+<div class="review">
+ <strong><%=h review.name %> says:</strong><br />
+ <%=h review.content %>
+</div>
@@ -0,0 +1,4 @@
+$("#new_review").before('<div id="flash_notice"><%= escape_javascript(flash.delete(:notice)) %></div>');
+$("#reviews_count").html("<%= pluralize(@review.product.reviews.count, 'Review') %>");
+$("#reviews").append("<%= escape_javascript(render(:partial => @review)) %>");
+$("#new_review")[0].reset();
Oops, something went wrong.

0 comments on commit 4d8e822

Please sign in to comment.