Permalink
Browse files

adding episode 185

  • Loading branch information...
1 parent e79a6ab commit b09f740d4790d935da4a2383e9f9826dc19e9065 @ryanb committed Oct 26, 2009
Showing with 9,318 additions and 0 deletions.
  1. +9 −0 episode-185/README
  2. +3 −0 episode-185/vet/.gitignore
  3. +1 −0 episode-185/vet/README
  4. +10 −0 episode-185/vet/Rakefile
  5. +44 −0 episode-185/vet/app/controllers/animals_controller.rb
  6. +10 −0 episode-185/vet/app/controllers/application_controller.rb
  7. +44 −0 episode-185/vet/app/controllers/categories_controller.rb
  8. +44 −0 episode-185/vet/app/controllers/problems_controller.rb
  9. +2 −0 episode-185/vet/app/helpers/animals_helper.rb
  10. +3 −0 episode-185/vet/app/helpers/application_helper.rb
  11. +2 −0 episode-185/vet/app/helpers/categories_helper.rb
  12. +22 −0 episode-185/vet/app/helpers/layout_helper.rb
  13. +2 −0 episode-185/vet/app/helpers/problems_helper.rb
  14. +7 −0 episode-185/vet/app/models/animal.rb
  15. +4 −0 episode-185/vet/app/models/category.rb
  16. +5 −0 episode-185/vet/app/models/problem.rb
  17. +5 −0 episode-185/vet/app/models/symptom.rb
  18. +11 −0 episode-185/vet/app/views/animals/_form.html.erb
  19. +8 −0 episode-185/vet/app/views/animals/edit.html.erb
  20. +23 −0 episode-185/vet/app/views/animals/index.html.erb
  21. +5 −0 episode-185/vet/app/views/animals/new.html.erb
  22. +24 −0 episode-185/vet/app/views/animals/show.html.erb
  23. +4 −0 episode-185/vet/app/views/categories/_form.html.erb
  24. +8 −0 episode-185/vet/app/views/categories/edit.html.erb
  25. +19 −0 episode-185/vet/app/views/categories/index.html.erb
  26. +5 −0 episode-185/vet/app/views/categories/new.html.erb
  27. +16 −0 episode-185/vet/app/views/categories/show.html.erb
  28. +22 −0 episode-185/vet/app/views/layouts/application.html.erb
  29. +8 −0 episode-185/vet/app/views/problems/_form.html.erb
  30. +8 −0 episode-185/vet/app/views/problems/edit.html.erb
  31. +17 −0 episode-185/vet/app/views/problems/index.html.erb
  32. +5 −0 episode-185/vet/app/views/problems/new.html.erb
  33. +12 −0 episode-185/vet/app/views/problems/show.html.erb
  34. +110 −0 episode-185/vet/config/boot.rb
  35. +22 −0 episode-185/vet/config/database.yml
  36. +42 −0 episode-185/vet/config/environment.rb
  37. +17 −0 episode-185/vet/config/environments/development.rb
  38. +28 −0 episode-185/vet/config/environments/production.rb
  39. +28 −0 episode-185/vet/config/environments/test.rb
  40. +7 −0 episode-185/vet/config/initializers/backtrace_silencers.rb
  41. +1 −0 episode-185/vet/config/initializers/formtastic_config.rb
  42. +10 −0 episode-185/vet/config/initializers/inflections.rb
  43. +5 −0 episode-185/vet/config/initializers/mime_types.rb
  44. +21 −0 episode-185/vet/config/initializers/new_rails_defaults.rb
  45. +15 −0 episode-185/vet/config/initializers/session_store.rb
  46. +5 −0 episode-185/vet/config/locales/en.yml
  47. +6 −0 episode-185/vet/config/routes.rb
  48. +13 −0 episode-185/vet/db/migrate/20091003190545_create_categories.rb
  49. +15 −0 episode-185/vet/db/migrate/20091003194015_create_animals.rb
  50. +12 −0 episode-185/vet/db/migrate/20091003205806_create_problems.rb
  51. +13 −0 episode-185/vet/db/migrate/20091003205938_create_symptoms.rb
  52. +43 −0 episode-185/vet/db/schema.rb
  53. +7 −0 episode-185/vet/db/seeds.rb
  54. +2 −0 episode-185/vet/doc/README_FOR_APP
  55. 0 episode-185/vet/log/.gitignore
  56. +30 −0 episode-185/vet/public/404.html
  57. +30 −0 episode-185/vet/public/422.html
  58. +30 −0 episode-185/vet/public/500.html
  59. 0 episode-185/vet/public/favicon.ico
  60. +2 −0 episode-185/vet/public/javascripts/application.js
  61. +963 −0 episode-185/vet/public/javascripts/controls.js
  62. +973 −0 episode-185/vet/public/javascripts/dragdrop.js
  63. +1,128 −0 episode-185/vet/public/javascripts/effects.js
  64. +4,320 −0 episode-185/vet/public/javascripts/prototype.js
  65. +5 −0 episode-185/vet/public/robots.txt
  66. +81 −0 episode-185/vet/public/stylesheets/application.css
  67. +137 −0 episode-185/vet/public/stylesheets/formtastic.css
  68. +15 −0 episode-185/vet/public/stylesheets/formtastic_changes.css
  69. +4 −0 episode-185/vet/script/about
  70. +3 −0 episode-185/vet/script/console
  71. +3 −0 episode-185/vet/script/dbconsole
  72. +3 −0 episode-185/vet/script/destroy
  73. +3 −0 episode-185/vet/script/generate
  74. +3 −0 episode-185/vet/script/performance/benchmarker
  75. +3 −0 episode-185/vet/script/performance/profiler
  76. +3 −0 episode-185/vet/script/plugin
  77. +3 −0 episode-185/vet/script/runner
  78. +3 −0 episode-185/vet/script/server
  79. +11 −0 episode-185/vet/test/fixtures/animals.yml
  80. +7 −0 episode-185/vet/test/fixtures/categories.yml
  81. +5 −0 episode-185/vet/test/fixtures/problems.yml
  82. +7 −0 episode-185/vet/test/fixtures/symptoms.yml
  83. +54 −0 episode-185/vet/test/functional/animals_controller_test.rb
  84. +54 −0 episode-185/vet/test/functional/categories_controller_test.rb
  85. +54 −0 episode-185/vet/test/functional/problems_controller_test.rb
  86. +9 −0 episode-185/vet/test/performance/browsing_test.rb
  87. +38 −0 episode-185/vet/test/test_helper.rb
  88. +7 −0 episode-185/vet/test/unit/animal_test.rb
  89. +7 −0 episode-185/vet/test/unit/category_test.rb
  90. +7 −0 episode-185/vet/test/unit/problem_test.rb
  91. +7 −0 episode-185/vet/test/unit/symptom_test.rb
  92. 0 episode-185/vet/tmp/.gitignore
  93. +29 −0 episode-185/vet/vendor/plugins/validation_reflection/CHANGELOG
  94. +20 −0 episode-185/vet/vendor/plugins/validation_reflection/LICENSE
  95. +64 −0 episode-185/vet/vendor/plugins/validation_reflection/README
  96. +36 −0 episode-185/vet/vendor/plugins/validation_reflection/Rakefile
  97. +4 −0 episode-185/vet/vendor/plugins/validation_reflection/VERSION.yml
  98. +7 −0 episode-185/vet/vendor/plugins/validation_reflection/about.yml
  99. +132 −0 episode-185/vet/vendor/plugins/validation_reflection/lib/validation_reflection.rb
  100. +1 −0 episode-185/vet/vendor/plugins/validation_reflection/rails/init.rb
  101. +6 −0 episode-185/vet/vendor/plugins/validation_reflection/test/test_helper.rb
  102. +122 −0 episode-185/vet/vendor/plugins/validation_reflection/test/validation_reflection_test.rb
  103. +51 −0 episode-185/vet/vendor/plugins/validation_reflection/validation_reflection.gemspec
View
@@ -0,0 +1,9 @@
+Railscasts Episode #185: Formtastic Part 2
+
+http://railscasts.com/episodes/185
+
+Commands
+
+ script/generate nifty_scaffold problem name:string
+ rake db:migrate
+ script/generate nifty_scaffold symptom animal_id:integer problem_id:integer --skip-controller
@@ -0,0 +1,3 @@
+log/*.log
+tmp/**/*
+*.sqlite3
View
@@ -0,0 +1 @@
+Example application for Railscasts episode.
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,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,44 @@
+class ProblemsController < ApplicationController
+ def index
+ @problems = Problem.all
+ end
+
+ def show
+ @problem = Problem.find(params[:id])
+ end
+
+ def new
+ @problem = Problem.new
+ end
+
+ def create
+ @problem = Problem.new(params[:problem])
+ if @problem.save
+ flash[:notice] = "Successfully created problem."
+ redirect_to @problem
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @problem = Problem.find(params[:id])
+ end
+
+ def update
+ @problem = Problem.find(params[:id])
+ if @problem.update_attributes(params[:problem])
+ flash[:notice] = "Successfully updated problem."
+ redirect_to @problem
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @problem = Problem.find(params[:id])
+ @problem.destroy
+ flash[:notice] = "Successfully destroyed problem."
+ redirect_to problems_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,2 @@
+module ProblemsHelper
+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,5 @@
+class Problem < ActiveRecord::Base
+ attr_accessible :name
+ has_many :symptoms
+ has_many :animals, :through => :symptoms
+end
@@ -0,0 +1,5 @@
+class Symptom < ActiveRecord::Base
+ attr_accessible :animal_id, :problem_id
+ belongs_to :animial
+ belongs_to :problem
+end
@@ -0,0 +1,11 @@
+<% semantic_form_for @animal do |f| %>
+ <%= f.error_messages %>
+ <% f.inputs do %>
+ <%= f.input :name, :hint => "Use the owner's name if none is provided" %>
+ <%= 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]] %>
+ <%= f.input :problems, :as => :check_boxes, :required => false %>
+ <% 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>
@@ -0,0 +1,8 @@
+<% form_for @problem do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
Oops, something went wrong.

0 comments on commit b09f740

Please sign in to comment.