Permalink
Browse files

adding episode 208

  • Loading branch information...
1 parent 21d87dd commit 6d6471df6b96f191667b7baec0c4fa7c3923499f @ryanb committed Apr 5, 2010
Showing with 8,586 additions and 0 deletions.
  1. +10 −0 episode-208/README
  2. +4 −0 episode-208/store/.gitignore
  3. +24 −0 episode-208/store/Gemfile
  4. +1 −0 episode-208/store/README
  5. +10 −0 episode-208/store/Rakefile
  6. +3 −0 episode-208/store/app/controllers/application_controller.rb
  7. +44 −0 episode-208/store/app/controllers/categories_controller.rb
  8. +44 −0 episode-208/store/app/controllers/products_controller.rb
  9. +9 −0 episode-208/store/app/helpers/application_helper.rb
  10. +2 −0 episode-208/store/app/helpers/categories_helper.rb
  11. +22 −0 episode-208/store/app/helpers/layout_helper.rb
  12. +2 −0 episode-208/store/app/helpers/products_helper.rb
  13. +3 −0 episode-208/store/app/models/category.rb
  14. +3 −0 episode-208/store/app/models/product.rb
  15. +8 −0 episode-208/store/app/views/categories/_form.html.erb
  16. +8 −0 episode-208/store/app/views/categories/edit.html.erb
  17. +17 −0 episode-208/store/app/views/categories/index.html.erb
  18. +5 −0 episode-208/store/app/views/categories/new.html.erb
  19. +12 −0 episode-208/store/app/views/categories/show.html.erb
  20. +23 −0 episode-208/store/app/views/layouts/application.html.erb
  21. +20 −0 episode-208/store/app/views/products/_form.html.erb
  22. +10 −0 episode-208/store/app/views/products/_product.html.erb
  23. +8 −0 episode-208/store/app/views/products/edit.html.erb
  24. +7 −0 episode-208/store/app/views/products/index.html.erb
  25. +5 −0 episode-208/store/app/views/products/new.html.erb
  26. +22 −0 episode-208/store/app/views/products/show.html.erb
  27. +4 −0 episode-208/store/config.ru
  28. +42 −0 episode-208/store/config/application.rb
  29. +17 −0 episode-208/store/config/boot.rb
  30. +22 −0 episode-208/store/config/database.yml
  31. +5 −0 episode-208/store/config/environment.rb
  32. +19 −0 episode-208/store/config/environments/development.rb
  33. +33 −0 episode-208/store/config/environments/production.rb
  34. +29 −0 episode-208/store/config/environments/test.rb
  35. +7 −0 episode-208/store/config/initializers/backtrace_silencers.rb
  36. +7 −0 episode-208/store/config/initializers/cookie_verification_secret.rb
  37. +10 −0 episode-208/store/config/initializers/inflections.rb
  38. +5 −0 episode-208/store/config/initializers/mime_types.rb
  39. +15 −0 episode-208/store/config/initializers/session_store.rb
  40. +5 −0 episode-208/store/config/locales/en.yml
  41. +5 −0 episode-208/store/config/routes.rb
  42. +15 −0 episode-208/store/db/migrate/20100313185049_create_products.rb
  43. +12 −0 episode-208/store/db/migrate/20100313203421_create_categories.rb
  44. +29 −0 episode-208/store/db/schema.rb
  45. +7 −0 episode-208/store/db/seeds.rb
  46. +2 −0 episode-208/store/doc/README_FOR_APP
  47. +1 −0 episode-208/store/lib/generators
  48. 0 episode-208/store/lib/tasks/.gitkeep
  49. +26 −0 episode-208/store/public/404.html
  50. +26 −0 episode-208/store/public/422.html
  51. +26 −0 episode-208/store/public/500.html
  52. 0 episode-208/store/public/favicon.ico
  53. BIN episode-208/store/public/images/rails.png
  54. +2 −0 episode-208/store/public/javascripts/application.js
  55. +963 −0 episode-208/store/public/javascripts/controls.js
  56. +973 −0 episode-208/store/public/javascripts/dragdrop.js
  57. +1,128 −0 episode-208/store/public/javascripts/effects.js
  58. +127 −0 episode-208/store/public/javascripts/jquery.rails.js
  59. +4,320 −0 episode-208/store/public/javascripts/prototype.js
  60. +110 −0 episode-208/store/public/javascripts/rails.js
  61. +5 −0 episode-208/store/public/robots.txt
  62. 0 episode-208/store/public/stylesheets/.gitkeep
  63. +95 −0 episode-208/store/public/stylesheets/application.css
  64. +10 −0 episode-208/store/script/rails
  65. +5 −0 episode-208/store/test/fixtures/categories.yml
  66. +9 −0 episode-208/store/test/fixtures/products.yml
  67. +54 −0 episode-208/store/test/functional/categories_controller_test.rb
  68. +54 −0 episode-208/store/test/functional/products_controller_test.rb
  69. +9 −0 episode-208/store/test/performance/browsing_test.rb
  70. +13 −0 episode-208/store/test/test_helper.rb
  71. +7 −0 episode-208/store/test/unit/category_test.rb
  72. +7 −0 episode-208/store/test/unit/product_test.rb
  73. 0 episode-208/store/vendor/plugins/.gitkeep
View
@@ -0,0 +1,10 @@
+Railscasts Episode #208: ERB Blocks in Rails 3
+
+http://railscasts.com/episodes/208
+
+Commands
+
+ rvm install ruby-head
+ rvm ruby-head
+ gem install rails --pre
+ bundle install
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
View
@@ -0,0 +1,24 @@
+# Edit this Gemfile to bundle your application's dependencies.
+source 'http://gemcutter.org'
+
+
+gem "rails", "3.0.0.beta2"
+
+## Bundle edge rails:
+# gem "rails", :git => "git://github.com/rails/rails.git"
+
+# ActiveRecord requires a database adapter. By default,
+# Rails has selected sqlite3.
+gem "sqlite3-ruby", :require => "sqlite3"
+
+## Bundle the gems you use:
+# gem "bj"
+# gem "hpricot", "0.6"
+# gem "sqlite3-ruby", :require => "sqlite3"
+# gem "aws-s3", :require => "aws/s3"
+
+## Bundle gems used only in certain environments:
+# gem "rspec", :group => :test
+# group :test do
+# gem "webrat"
+# end
View
@@ -0,0 +1 @@
+Example application for Railscasts.
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.expand_path('../config/application', __FILE__)
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+Rails::Application.load_tasks
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,44 @@
+class CategoriesController < ApplicationController
+ def index
+ @categories = Category.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
+ 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,9 @@
+module ApplicationHelper
+ def admin_area(&block)
+ content_tag(:div, :class => "admin", &block) if admin?
+ end
+
+ def admin?
+ true
+ end
+end
@@ -0,0 +1,2 @@
+module CategoriesHelper
+end
@@ -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] = 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,2 @@
+module ProductsHelper
+end
@@ -0,0 +1,3 @@
+class Category < ActiveRecord::Base
+ has_many :products
+end
@@ -0,0 +1,3 @@
+class Product < ActiveRecord::Base
+ belongs_to :category
+end
@@ -0,0 +1,8 @@
+<% form_for @category do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Category" %>
+
+<%= render 'form' %>
+
+<p>
+ <%= link_to "Show", @category %> |
+ <%= link_to "View All", categories_path %>
+</p>
@@ -0,0 +1,17 @@
+<% title "Categories" %>
+
+<table>
+ <tr>
+ <th>Name</th>
+ </tr>
+ <% for category in @categories %>
+ <tr>
+ <td><%= category.name %></td>
+ <td><%= link_to "Show", category %></td>
+ <td><%= link_to "Edit", edit_category_path(category) %></td>
+ <td><%= link_to "Destroy", category, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+ <% end %>
+</table>
+
+<p><%= link_to "New Category", new_category_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Category" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", categories_path %></p>
@@ -0,0 +1,12 @@
+<% title "Category" %>
+
+<p>
+ <strong>Name:</strong>
+ <%= @category.name %>
+</p>
+
+<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>
+<html>
+ <head>
+ <title><%= h(yield(:title) || "Untitled") %></title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "jquery.rails.js" %>
+ <%= csrf_meta_tag %>
+ <%= 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,20 @@
+<%= form_for @product do |f| %>
+ <%= f.error_messages %>
+ <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,10 @@
+<div class="product">
+ <h3>
+ <%= link_to 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>
@@ -0,0 +1,8 @@
+<% title "Edit Product" %>
+
+<%= render 'form' %>
+
+<p>
+ <%= link_to "Show", @product %> |
+ <%= link_to "View All", products_path %>
+</p>
@@ -0,0 +1,7 @@
+<% title "Products" %>
+
+<div id="products">
+ <%= render @products %>
+</div>
+
+<p><%= link_to "New Product", new_product_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Product" %>
+
+<%= render 'form' %>
+
+<p><%= link_to "Back to List", products_path %></p>
@@ -0,0 +1,22 @@
+<% title "Product" %>
+
+<p>
+ <strong>Name:</strong>
+ <%= @product.name %>
+</p>
+<% unless @product.category.nil? %>
+<p>
+ <strong>Category:</strong>
+ <%= link_to @product.category.name, @product.category %>
+</p>
+<% end %>
+<p>
+ <strong>Price:</strong>
+ <%= number_to_currency @product.price %>
+</p>
+
+<%= admin_area do %>
+ <%= link_to "Edit", edit_product_path(@product) %> |
+ <%= link_to "Destroy", @product, :confirm => "Are you sure?", :method => :delete %> |
+ <%= link_to "View All", products_path %>
+<% end %>
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Store::Application
Oops, something went wrong.

0 comments on commit 6d6471d

Please sign in to comment.