Permalink
Browse files

adding episode 184

  • Loading branch information...
1 parent 0eee9ea commit e79a6ab8e0d5784b13cf70f11c2d8bf489b06bc2 @ryanb committed Oct 19, 2009
Showing with 9,102 additions and 0 deletions.
  1. +13 −0 episode-184/README
  2. +3 −0 episode-184/vet/.gitignore
  3. +1 −0 episode-184/vet/README
  4. +10 −0 episode-184/vet/Rakefile
  5. +44 −0 episode-184/vet/app/controllers/animals_controller.rb
  6. +10 −0 episode-184/vet/app/controllers/application_controller.rb
  7. +44 −0 episode-184/vet/app/controllers/categories_controller.rb
  8. +2 −0 episode-184/vet/app/helpers/animals_helper.rb
  9. +3 −0 episode-184/vet/app/helpers/application_helper.rb
  10. +2 −0 episode-184/vet/app/helpers/categories_helper.rb
  11. +22 −0 episode-184/vet/app/helpers/layout_helper.rb
  12. +7 −0 episode-184/vet/app/models/animal.rb
  13. +4 −0 episode-184/vet/app/models/category.rb
  14. +9 −0 episode-184/vet/app/views/animals/_form.html.erb
  15. +8 −0 episode-184/vet/app/views/animals/edit.html.erb
  16. +23 −0 episode-184/vet/app/views/animals/index.html.erb
  17. +5 −0 episode-184/vet/app/views/animals/new.html.erb
  18. +24 −0 episode-184/vet/app/views/animals/show.html.erb
  19. +4 −0 episode-184/vet/app/views/categories/_form.html.erb
  20. +8 −0 episode-184/vet/app/views/categories/edit.html.erb
  21. +19 −0 episode-184/vet/app/views/categories/index.html.erb
  22. +5 −0 episode-184/vet/app/views/categories/new.html.erb
  23. +16 −0 episode-184/vet/app/views/categories/show.html.erb
  24. +22 −0 episode-184/vet/app/views/layouts/application.html.erb
  25. +110 −0 episode-184/vet/config/boot.rb
  26. +22 −0 episode-184/vet/config/database.yml
  27. +42 −0 episode-184/vet/config/environment.rb
  28. +17 −0 episode-184/vet/config/environments/development.rb
  29. +28 −0 episode-184/vet/config/environments/production.rb
  30. +28 −0 episode-184/vet/config/environments/test.rb
  31. +7 −0 episode-184/vet/config/initializers/backtrace_silencers.rb
  32. +10 −0 episode-184/vet/config/initializers/inflections.rb
  33. +5 −0 episode-184/vet/config/initializers/mime_types.rb
  34. +21 −0 episode-184/vet/config/initializers/new_rails_defaults.rb
  35. +15 −0 episode-184/vet/config/initializers/session_store.rb
  36. +5 −0 episode-184/vet/config/locales/en.yml
  37. +5 −0 episode-184/vet/config/routes.rb
  38. +13 −0 episode-184/vet/db/migrate/20091003190545_create_categories.rb
  39. +15 −0 episode-184/vet/db/migrate/20091003194015_create_animals.rb
  40. +43 −0 episode-184/vet/db/schema.rb
  41. +7 −0 episode-184/vet/db/seeds.rb
  42. +2 −0 episode-184/vet/doc/README_FOR_APP
  43. +30 −0 episode-184/vet/public/404.html
  44. +30 −0 episode-184/vet/public/422.html
  45. +30 −0 episode-184/vet/public/500.html
  46. 0 episode-184/vet/public/favicon.ico
  47. +2 −0 episode-184/vet/public/javascripts/application.js
  48. +963 −0 episode-184/vet/public/javascripts/controls.js
  49. +973 −0 episode-184/vet/public/javascripts/dragdrop.js
  50. +1,128 −0 episode-184/vet/public/javascripts/effects.js
  51. +4,320 −0 episode-184/vet/public/javascripts/prototype.js
  52. +5 −0 episode-184/vet/public/robots.txt
  53. +81 −0 episode-184/vet/public/stylesheets/application.css
  54. +137 −0 episode-184/vet/public/stylesheets/formtastic.css
  55. +10 −0 episode-184/vet/public/stylesheets/formtastic_changes.css
  56. +4 −0 episode-184/vet/script/about
  57. +3 −0 episode-184/vet/script/console
  58. +3 −0 episode-184/vet/script/dbconsole
  59. +3 −0 episode-184/vet/script/destroy
  60. +3 −0 episode-184/vet/script/generate
  61. +3 −0 episode-184/vet/script/performance/benchmarker
  62. +3 −0 episode-184/vet/script/performance/profiler
  63. +3 −0 episode-184/vet/script/plugin
  64. +3 −0 episode-184/vet/script/runner
  65. +3 −0 episode-184/vet/script/server
  66. +11 −0 episode-184/vet/test/fixtures/animals.yml
  67. +7 −0 episode-184/vet/test/fixtures/categories.yml
  68. +54 −0 episode-184/vet/test/functional/animals_controller_test.rb
  69. +54 −0 episode-184/vet/test/functional/categories_controller_test.rb
  70. +9 −0 episode-184/vet/test/performance/browsing_test.rb
  71. +38 −0 episode-184/vet/test/test_helper.rb
  72. +7 −0 episode-184/vet/test/unit/animal_test.rb
  73. +7 −0 episode-184/vet/test/unit/category_test.rb
  74. +29 −0 episode-184/vet/vendor/plugins/validation_reflection/CHANGELOG
  75. +20 −0 episode-184/vet/vendor/plugins/validation_reflection/LICENSE
  76. +64 −0 episode-184/vet/vendor/plugins/validation_reflection/README
  77. +36 −0 episode-184/vet/vendor/plugins/validation_reflection/Rakefile
  78. +4 −0 episode-184/vet/vendor/plugins/validation_reflection/VERSION.yml
  79. +7 −0 episode-184/vet/vendor/plugins/validation_reflection/about.yml
  80. +132 −0 episode-184/vet/vendor/plugins/validation_reflection/lib/validation_reflection.rb
  81. +1 −0 episode-184/vet/vendor/plugins/validation_reflection/rails/init.rb
  82. +6 −0 episode-184/vet/vendor/plugins/validation_reflection/test/test_helper.rb
  83. +122 −0 episode-184/vet/vendor/plugins/validation_reflection/test/validation_reflection_test.rb
  84. +51 −0 episode-184/vet/vendor/plugins/validation_reflection/validation_reflection.gemspec
View
@@ -0,0 +1,13 @@
+Railscasts Episode #184: Formtastic Part 1
+
+http://railscasts.com/episodes/184
+
+Commands
+
+ rails vet
+ sudo rake gems:install
+ script/generate nifty_layout
+ script/generate nifty_scaffold category name:string description:text
+ rake db:migrate
+ script/generate formtastic_stylesheets
+ script/generate nifty_scaffold animal name:string category_id:integer born_on:date female:boolean
@@ -0,0 +1,3 @@
+log/*.log
+tmp/**/*
+*.sqlite3
@@ -0,0 +1 @@
+Example application used in Railscasts.
@@ -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,44 @@
+class AnimalsController < ApplicationController
+ def index
+ @animals = Animal.all
+ end
+
+ def show
+ @animal = Animal.find(params[:id])
+ end
+
+ def new
+ @animal = Animal.new
+ end
+
+ def create
+ @animal = Animal.new(params[:animal])
+ if @animal.save
+ flash[:notice] = "Successfully created animal."
+ redirect_to @animal
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @animal = Animal.find(params[:id])
+ end
+
+ def update
+ @animal = Animal.find(params[:id])
+ if @animal.update_attributes(params[:animal])
+ flash[:notice] = "Successfully updated animal."
+ redirect_to @animal
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @animal = Animal.find(params[:id])
+ @animal.destroy
+ flash[:notice] = "Successfully destroyed animal."
+ redirect_to animals_url
+ end
+end
@@ -0,0 +1,10 @@
+# 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
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
+
+ # Scrub sensitive parameters from your log
+ # filter_parameter_logging :password
+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,2 @@
+module AnimalsHelper
+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,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,7 @@
+class Animal < ActiveRecord::Base
+ attr_accessible :name, :category_id, :born_on, :female, :problem_ids
+ belongs_to :category
+ has_many :symptoms
+ has_many :problems, :through => :symptoms
+ validates_presence_of :name, :born_on
+end
@@ -0,0 +1,4 @@
+class Category < ActiveRecord::Base
+ attr_accessible :name, :description
+ has_many :animals
+end
@@ -0,0 +1,9 @@
+<% semantic_form_for @animal do |f| %>
+ <% f.inputs do %>
+ <%= f.input :name %>
+ <%= f.input :born_on, :start_year => 1900 %>
+ <%= f.input :category, :include_blank => false %>
+ <%= f.input :female, :as => :radio, :label => "Gender", :collection => [["Male", false], ["Female", true]] %>
+ <% end %>
+ <%= f.buttons %>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Animal" %>
+
+<%= render :partial => 'form' %>
+
+<p>
+ <%= link_to "Show", @animal %> |
+ <%= link_to "View All", animals_path %>
+</p>
@@ -0,0 +1,23 @@
+<% title "Animals" %>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Category</th>
+ <th>Born On</th>
+ <th>Female</th>
+ </tr>
+ <% for animal in @animals %>
+ <tr>
+ <td><%=h animal.name %></td>
+ <td><%=h animal.category_id %></td>
+ <td><%=h animal.born_on %></td>
+ <td><%=h animal.female %></td>
+ <td><%= link_to "Show", animal %></td>
+ <td><%= link_to "Edit", edit_animal_path(animal) %></td>
+ <td><%= link_to "Destroy", animal, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+ <% end %>
+</table>
+
+<p><%= link_to "New Animal", new_animal_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Animal" %>
+
+<%= render :partial => 'form' %>
+
+<p><%= link_to "Back to List", animals_path %></p>
@@ -0,0 +1,24 @@
+<% title "Animal" %>
+
+<p>
+ <strong>Name:</strong>
+ <%=h @animal.name %>
+</p>
+<p>
+ <strong>Category:</strong>
+ <%=h @animal.category_id %>
+</p>
+<p>
+ <strong>Born On:</strong>
+ <%=h @animal.born_on %>
+</p>
+<p>
+ <strong>Female:</strong>
+ <%=h @animal.female %>
+</p>
+
+<p>
+ <%= link_to "Edit", edit_animal_path(@animal) %> |
+ <%= link_to "Destroy", @animal, :confirm => 'Are you sure?', :method => :delete %> |
+ <%= link_to "View All", animals_path %>
+</p>
@@ -0,0 +1,4 @@
+<% semantic_form_for @category do |f| %>
+ <%= f.inputs %>
+ <%= f.buttons %>
+<% 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,19 @@
+<% title "Categories" %>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Description</th>
+ </tr>
+ <% for category in @categories %>
+ <tr>
+ <td><%=h category.name %></td>
+ <td><%=h category.description %></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 :partial => 'form' %>
+
+<p><%= link_to "Back to List", categories_path %></p>
@@ -0,0 +1,16 @@
+<% title "Category" %>
+
+<p>
+ <strong>Name:</strong>
+ <%=h @category.name %>
+</p>
+<p>
+ <strong>Description:</strong>
+ <%=h @category.description %>
+</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,22 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <title><%= h(yield(:title) || "Untitled") %></title>
+ <%= stylesheet_link_tag 'application', 'formtastic', 'formtastic_changes', :cache => "base" %>
+ <%= 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 e79a6ab

Please sign in to comment.