Skip to content
This repository
Browse code

adding episode 194

  • Loading branch information...
commit bfeeb60c8b551e78d4c4ac6c8f0b1766f312f206 1 parent 5b12b65
Ryan Bates authored

Showing 71 changed files with 8,419 additions and 0 deletions. Show diff stats Hide diff stats

  1. +11 0 episode-194/README
  2. +2 0  episode-194/todo/.gitignore
  3. +1 0  episode-194/todo/README
  4. +10 0 episode-194/todo/Rakefile
  5. +10 0 episode-194/todo/app/controllers/application_controller.rb
  6. +44 0 episode-194/todo/app/controllers/projects_controller.rb
  7. +44 0 episode-194/todo/app/controllers/tasks_controller.rb
  8. +3 0  episode-194/todo/app/helpers/application_helper.rb
  9. +22 0 episode-194/todo/app/helpers/layout_helper.rb
  10. +2 0  episode-194/todo/app/helpers/projects_helper.rb
  11. +2 0  episode-194/todo/app/helpers/tasks_helper.rb
  12. +8 0 episode-194/todo/app/models/project.rb
  13. +9 0 episode-194/todo/app/models/task.rb
  14. +22 0 episode-194/todo/app/views/layouts/application.html.erb
  15. +12 0 episode-194/todo/app/views/projects/_form.html.erb
  16. +8 0 episode-194/todo/app/views/projects/edit.html.erb
  17. +17 0 episode-194/todo/app/views/projects/index.html.erb
  18. +5 0 episode-194/todo/app/views/projects/new.html.erb
  19. +16 0 episode-194/todo/app/views/projects/show.html.erb
  20. +16 0 episode-194/todo/app/views/tasks/_form.html.erb
  21. +8 0 episode-194/todo/app/views/tasks/edit.html.erb
  22. +21 0 episode-194/todo/app/views/tasks/index.html.erb
  23. +5 0 episode-194/todo/app/views/tasks/new.html.erb
  24. +20 0 episode-194/todo/app/views/tasks/show.html.erb
  25. +110 0 episode-194/todo/config/boot.rb
  26. +22 0 episode-194/todo/config/database.yml
  27. +42 0 episode-194/todo/config/environment.rb
  28. +17 0 episode-194/todo/config/environments/development.rb
  29. +28 0 episode-194/todo/config/environments/production.rb
  30. +28 0 episode-194/todo/config/environments/test.rb
  31. +7 0 episode-194/todo/config/initializers/backtrace_silencers.rb
  32. +10 0 episode-194/todo/config/initializers/inflections.rb
  33. +5 0 episode-194/todo/config/initializers/mime_types.rb
  34. +1 0  episode-194/todo/config/initializers/mongo_config.rb
  35. +21 0 episode-194/todo/config/initializers/new_rails_defaults.rb
  36. +15 0 episode-194/todo/config/initializers/session_store.rb
  37. +5 0 episode-194/todo/config/locales/en.yml
  38. +5 0 episode-194/todo/config/routes.rb
  39. 0  episode-194/todo/db/development.sqlite3
  40. +7 0 episode-194/todo/db/seeds.rb
  41. +2 0  episode-194/todo/doc/README_FOR_APP
  42. +30 0 episode-194/todo/public/404.html
  43. +30 0 episode-194/todo/public/422.html
  44. +30 0 episode-194/todo/public/500.html
  45. 0  episode-194/todo/public/favicon.ico
  46. BIN  episode-194/todo/public/images/rails.png
  47. +2 0  episode-194/todo/public/javascripts/application.js
  48. +963 0 episode-194/todo/public/javascripts/controls.js
  49. +973 0 episode-194/todo/public/javascripts/dragdrop.js
  50. +1,128 0 episode-194/todo/public/javascripts/effects.js
  51. +4,320 0 episode-194/todo/public/javascripts/prototype.js
  52. +5 0 episode-194/todo/public/robots.txt
  53. +81 0 episode-194/todo/public/stylesheets/application.css
  54. +4 0 episode-194/todo/script/about
  55. +3 0  episode-194/todo/script/console
  56. +3 0  episode-194/todo/script/dbconsole
  57. +3 0  episode-194/todo/script/destroy
  58. +3 0  episode-194/todo/script/generate
  59. +3 0  episode-194/todo/script/performance/benchmarker
  60. +3 0  episode-194/todo/script/performance/profiler
  61. +3 0  episode-194/todo/script/plugin
  62. +3 0  episode-194/todo/script/runner
  63. +3 0  episode-194/todo/script/server
  64. +5 0 episode-194/todo/test/fixtures/projects.yml
  65. +9 0 episode-194/todo/test/fixtures/tasks.yml
  66. +54 0 episode-194/todo/test/functional/projects_controller_test.rb
  67. +54 0 episode-194/todo/test/functional/tasks_controller_test.rb
  68. +9 0 episode-194/todo/test/performance/browsing_test.rb
  69. +38 0 episode-194/todo/test/test_helper.rb
  70. +7 0 episode-194/todo/test/unit/project_test.rb
  71. +7 0 episode-194/todo/test/unit/task_test.rb
11 episode-194/README
... ... @@ -0,0 +1,11 @@
  1 +Railscasts Episode #194: MongoMapper Basics
  2 +
  3 +http://railscasts.com/episodes/194
  4 +
  5 +script/console
  6 +
  7 + Project.all
  8 + Project.all(:order => "name")
  9 + Project.all(:priority => 3)
  10 + Project.all(:priority.gte => 2)
  11 + Project.all(:priority.in => [2, 3])
2  episode-194/todo/.gitignore
... ... @@ -0,0 +1,2 @@
  1 +log/*.log
  2 +tmp/**/*
1  episode-194/todo/README
... ... @@ -0,0 +1 @@
  1 +Example Railscasts application.
10 episode-194/todo/Rakefile
... ... @@ -0,0 +1,10 @@
  1 +# Add your own tasks in files placed in lib/tasks ending in .rake,
  2 +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
  3 +
  4 +require(File.join(File.dirname(__FILE__), 'config', 'boot'))
  5 +
  6 +require 'rake'
  7 +require 'rake/testtask'
  8 +require 'rake/rdoctask'
  9 +
  10 +require 'tasks/rails'
10 episode-194/todo/app/controllers/application_controller.rb
... ... @@ -0,0 +1,10 @@
  1 +# Filters added to this controller apply to all controllers in the application.
  2 +# Likewise, all the methods added will be available for all controllers.
  3 +
  4 +class ApplicationController < ActionController::Base
  5 + helper :all # include all helpers, all the time
  6 + protect_from_forgery # See ActionController::RequestForgeryProtection for details
  7 +
  8 + # Scrub sensitive parameters from your log
  9 + # filter_parameter_logging :password
  10 +end
44 episode-194/todo/app/controllers/projects_controller.rb
... ... @@ -0,0 +1,44 @@
  1 +class ProjectsController < ApplicationController
  2 + def index
  3 + @projects = Project.all
  4 + end
  5 +
  6 + def show
  7 + @project = Project.find(params[:id])
  8 + end
  9 +
  10 + def new
  11 + @project = Project.new
  12 + end
  13 +
  14 + def create
  15 + @project = Project.new(params[:project])
  16 + if @project.save
  17 + flash[:notice] = "Successfully created project."
  18 + redirect_to @project
  19 + else
  20 + render :action => 'new'
  21 + end
  22 + end
  23 +
  24 + def edit
  25 + @project = Project.find(params[:id])
  26 + end
  27 +
  28 + def update
  29 + @project = Project.find(params[:id])
  30 + if @project.update_attributes(params[:project])
  31 + flash[:notice] = "Successfully updated project."
  32 + redirect_to @project
  33 + else
  34 + render :action => 'edit'
  35 + end
  36 + end
  37 +
  38 + def destroy
  39 + @project = Project.find(params[:id])
  40 + @project.destroy
  41 + flash[:notice] = "Successfully destroyed project."
  42 + redirect_to projects_url
  43 + end
  44 +end
44 episode-194/todo/app/controllers/tasks_controller.rb
... ... @@ -0,0 +1,44 @@
  1 +class TasksController < ApplicationController
  2 + def index
  3 + @tasks = Task.all
  4 + end
  5 +
  6 + def show
  7 + @task = Task.find(params[:id])
  8 + end
  9 +
  10 + def new
  11 + @task = Task.new
  12 + end
  13 +
  14 + def create
  15 + @task = Task.new(params[:task])
  16 + if @task.save
  17 + flash[:notice] = "Successfully created task."
  18 + redirect_to @task
  19 + else
  20 + render :action => 'new'
  21 + end
  22 + end
  23 +
  24 + def edit
  25 + @task = Task.find(params[:id])
  26 + end
  27 +
  28 + def update
  29 + @task = Task.find(params[:id])
  30 + if @task.update_attributes(params[:task])
  31 + flash[:notice] = "Successfully updated task."
  32 + redirect_to @task
  33 + else
  34 + render :action => 'edit'
  35 + end
  36 + end
  37 +
  38 + def destroy
  39 + @task = Task.find(params[:id])
  40 + @task.destroy
  41 + flash[:notice] = "Successfully destroyed task."
  42 + redirect_to tasks_url
  43 + end
  44 +end
3  episode-194/todo/app/helpers/application_helper.rb
... ... @@ -0,0 +1,3 @@
  1 +# Methods added to this helper will be available to all templates in the application.
  2 +module ApplicationHelper
  3 +end
22 episode-194/todo/app/helpers/layout_helper.rb
... ... @@ -0,0 +1,22 @@
  1 +# These helper methods can be called in your template to set variables to be used in the layout
  2 +# This module should be included in all views globally,
  3 +# to do so you may need to add this line to your ApplicationController
  4 +# helper :layout
  5 +module LayoutHelper
  6 + def title(page_title, show_title = true)
  7 + @content_for_title = page_title.to_s
  8 + @show_title = show_title
  9 + end
  10 +
  11 + def show_title?
  12 + @show_title
  13 + end
  14 +
  15 + def stylesheet(*args)
  16 + content_for(:head) { stylesheet_link_tag(*args) }
  17 + end
  18 +
  19 + def javascript(*args)
  20 + content_for(:head) { javascript_include_tag(*args) }
  21 + end
  22 +end
2  episode-194/todo/app/helpers/projects_helper.rb
... ... @@ -0,0 +1,2 @@
  1 +module ProjectsHelper
  2 +end
2  episode-194/todo/app/helpers/tasks_helper.rb
... ... @@ -0,0 +1,2 @@
  1 +module TasksHelper
  2 +end
8 episode-194/todo/app/models/project.rb
... ... @@ -0,0 +1,8 @@
  1 +class Project
  2 + include MongoMapper::Document
  3 +
  4 + key :name, String, :required => true
  5 + key :priority, Integer
  6 +
  7 + many :tasks
  8 +end
9 episode-194/todo/app/models/task.rb
... ... @@ -0,0 +1,9 @@
  1 +class Task
  2 + include MongoMapper::Document
  3 +
  4 + key :project_id, ObjectId
  5 + key :name, String
  6 + key :completed, Boolean
  7 +
  8 + belongs_to :project
  9 +end
22 episode-194/todo/app/views/layouts/application.html.erb
... ... @@ -0,0 +1,22 @@
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3 +<html>
  4 + <head>
  5 + <title><%= h(yield(:title) || "Untitled") %></title>
  6 + <%= stylesheet_link_tag 'application' %>
  7 + <%= yield(:head) %>
  8 + </head>
  9 + <body>
  10 + <div id="container">
  11 + <%- flash.each do |name, msg| -%>
  12 + <%= content_tag :div, msg, :id => "flash_#{name}" %>
  13 + <%- end -%>
  14 +
  15 + <%- if show_title? -%>
  16 + <h1><%=h yield(:title) %></h1>
  17 + <%- end -%>
  18 +
  19 + <%= yield %>
  20 + </div>
  21 + </body>
  22 +</html>
12 episode-194/todo/app/views/projects/_form.html.erb
... ... @@ -0,0 +1,12 @@
  1 +<% form_for @project do |f| %>
  2 + <%= f.error_messages %>
  3 + <p>
  4 + <%= f.label :name %><br />
  5 + <%= f.text_field :name %>
  6 + </p>
  7 + <p>
  8 + <%= f.label :priority %><br />
  9 + <%= f.select :priority, [1,2,3,4,5] %>
  10 + </p>
  11 + <p><%= f.submit "Submit" %></p>
  12 +<% end %>
8 episode-194/todo/app/views/projects/edit.html.erb
... ... @@ -0,0 +1,8 @@
  1 +<% title "Edit Project" %>
  2 +
  3 +<%= render :partial => 'form' %>
  4 +
  5 +<p>
  6 + <%= link_to "Show", @project %> |
  7 + <%= link_to "View All", projects_path %>
  8 +</p>
17 episode-194/todo/app/views/projects/index.html.erb
... ... @@ -0,0 +1,17 @@
  1 +<% title "Projects" %>
  2 +
  3 +<table>
  4 + <tr>
  5 + <th>Name</th>
  6 + </tr>
  7 + <% for project in @projects %>
  8 + <tr>
  9 + <td><%=h project.name %></td>
  10 + <td><%= link_to "Show", project %></td>
  11 + <td><%= link_to "Edit", edit_project_path(project) %></td>
  12 + <td><%= link_to "Destroy", project, :confirm => 'Are you sure?', :method => :delete %></td>
  13 + </tr>
  14 + <% end %>
  15 +</table>
  16 +
  17 +<p><%= link_to "New Project", new_project_path %></p>
5 episode-194/todo/app/views/projects/new.html.erb
... ... @@ -0,0 +1,5 @@
  1 +<% title "New Project" %>
  2 +
  3 +<%= render :partial => 'form' %>
  4 +
  5 +<p><%= link_to "Back to List", projects_path %></p>
16 episode-194/todo/app/views/projects/show.html.erb
... ... @@ -0,0 +1,16 @@
  1 +<% title "Project" %>
  2 +
  3 +<p>
  4 + <strong>Name:</strong>
  5 + <%=h @project.name %>
  6 +</p>
  7 +<p>
  8 + <strong>Priority:</strong>
  9 + <%=h @project.priority %>
  10 +</p>
  11 +
  12 +<p>
  13 + <%= link_to "Edit", edit_project_path(@project) %> |
  14 + <%= link_to "Destroy", @project, :confirm => 'Are you sure?', :method => :delete %> |
  15 + <%= link_to "View All", projects_path %>
  16 +</p>
16 episode-194/todo/app/views/tasks/_form.html.erb
... ... @@ -0,0 +1,16 @@
  1 +<% form_for @task do |f| %>
  2 + <%= f.error_messages %>
  3 + <p>
  4 + <%= f.label :project_id %><br />
  5 + <%= f.collection_select :project_id, Project.all, :id, :name %>
  6 + </p>
  7 + <p>
  8 + <%= f.label :name %><br />
  9 + <%= f.text_field :name %>
  10 + </p>
  11 + <p>
  12 + <%= f.label :completed %><br />
  13 + <%= f.check_box :completed %>
  14 + </p>
  15 + <p><%= f.submit "Submit" %></p>
  16 +<% end %>
8 episode-194/todo/app/views/tasks/edit.html.erb
... ... @@ -0,0 +1,8 @@
  1 +<% title "Edit Task" %>
  2 +
  3 +<%= render :partial => 'form' %>
  4 +
  5 +<p>
  6 + <%= link_to "Show", @task %> |
  7 + <%= link_to "View All", tasks_path %>
  8 +</p>
21 episode-194/todo/app/views/tasks/index.html.erb
... ... @@ -0,0 +1,21 @@
  1 +<% title "Tasks" %>
  2 +
  3 +<table>
  4 + <tr>
  5 + <th>Project</th>
  6 + <th>Name</th>
  7 + <th>Completed</th>
  8 + </tr>
  9 + <% for task in @tasks %>
  10 + <tr>
  11 + <td><%=h task.project_id %></td>
  12 + <td><%=h task.name %></td>
  13 + <td><%=h task.completed %></td>
  14 + <td><%= link_to "Show", task %></td>
  15 + <td><%= link_to "Edit", edit_task_path(task) %></td>
  16 + <td><%= link_to "Destroy", task, :confirm => 'Are you sure?', :method => :delete %></td>
  17 + </tr>
  18 + <% end %>
  19 +</table>
  20 +
  21 +<p><%= link_to "New Task", new_task_path %></p>
5 episode-194/todo/app/views/tasks/new.html.erb
... ... @@ -0,0 +1,5 @@
  1 +<% title "New Task" %>
  2 +
  3 +<%= render :partial => 'form' %>
  4 +
  5 +<p><%= link_to "Back to List", tasks_path %></p>
20 episode-194/todo/app/views/tasks/show.html.erb
... ... @@ -0,0 +1,20 @@
  1 +<% title "Task" %>
  2 +
  3 +<p>
  4 + <strong>Project:</strong>
  5 + <%=h @task.project.name %>
  6 +</p>
  7 +<p>
  8 + <strong>Name:</strong>
  9 + <%=h @task.name %>
  10 +</p>
  11 +<p>
  12 + <strong>Completed:</strong>
  13 + <%=h @task.completed %>
  14 +</p>
  15 +
  16 +<p>
  17 + <%= link_to "Edit", edit_task_path(@task) %> |
  18 + <%= link_to "Destroy", @task, :confirm => 'Are you sure?', :method => :delete %> |
  19 + <%= link_to "View All", tasks_path %>
  20 +</p>
110 episode-194/todo/config/boot.rb
... ... @@ -0,0 +1,110 @@
  1 +# Don't change this file!
  2 +# Configure your app in config/environment.rb and config/environments/*.rb
  3 +
  4 +RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
  5 +
  6 +module Rails
  7 + class << self
  8 + def boot!
  9 + unless booted?
  10 + preinitialize
  11 + pick_boot.run
  12 + end
  13 + end
  14 +
  15 + def booted?
  16 + defined? Rails::Initializer
  17 + end
  18 +
  19 + def pick_boot
  20 + (vendor_rails? ? VendorBoot : GemBoot).new
  21 + end
  22 +
  23 + def vendor_rails?
  24 + File.exist?("#{RAILS_ROOT}/vendor/rails")
  25 + end
  26 +
  27 + def preinitialize
  28 + load(preinitializer_path) if File.exist?(preinitializer_path)
  29 + end
  30 +
  31 + def preinitializer_path
  32 + "#{RAILS_ROOT}/config/preinitializer.rb"
  33 + end
  34 + end
  35 +
  36 + class Boot
  37 + def run
  38 + load_initializer
  39 + Rails::Initializer.run(:set_load_path)
  40 + end
  41 + end
  42 +
  43 + class VendorBoot < Boot
  44 + def load_initializer
  45 + require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
  46 + Rails::Initializer.run(:install_gem_spec_stubs)
  47 + Rails::GemDependency.add_frozen_gem_path
  48 + end
  49 + end
  50 +
  51 + class GemBoot < Boot
  52 + def load_initializer
  53 + self.class.load_rubygems
  54 + load_rails_gem
  55 + require 'initializer'
  56 + end
  57 +
  58 + def load_rails_gem
  59 + if version = self.class.gem_version
  60 + gem 'rails', version
  61 + else
  62 + gem 'rails'
  63 + end
  64 + rescue Gem::LoadError => load_error
  65 + $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
  66 + exit 1
  67 + end
  68 +
  69 + class << self
  70 + def rubygems_version
  71 + Gem::RubyGemsVersion rescue nil
  72 + end
  73 +
  74 + def gem_version
  75 + if defined? RAILS_GEM_VERSION
  76 + RAILS_GEM_VERSION
  77 + elsif ENV.include?('RAILS_GEM_VERSION')
  78 + ENV['RAILS_GEM_VERSION']
  79 + else
  80 + parse_gem_version(read_environment_rb)
  81 + end
  82 + end
  83 +
  84 + def load_rubygems
  85 + min_version = '1.3.2'
  86 + require 'rubygems'
  87 + unless rubygems_version >= min_version
  88 + $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
  89 + exit 1
  90 + end
  91 +
  92 + rescue LoadError
  93 + $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
  94 + exit 1
  95 + end
  96 +
  97 + def parse_gem_version(text)
  98 + $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
  99 + end
  100 +
  101 + private
  102 + def read_environment_rb
  103 + File.read("#{RAILS_ROOT}/config/environment.rb")
  104 + end
  105 + end
  106 + end
  107 +end
  108 +
  109 +# All that for this:
  110 +Rails.boot!
22 episode-194/todo/config/database.yml
... ... @@ -0,0 +1,22 @@
  1 +# SQLite version 3.x
  2 +# gem install sqlite3-ruby (not necessary on OS X Leopard)
  3 +development:
  4 + adapter: sqlite3
  5 + database: db/development.sqlite3
  6 + pool: 5
  7 + timeout: 5000
  8 +
  9 +# Warning: The database defined as "test" will be erased and
  10 +# re-generated from your development database when you run "rake".
  11 +# Do not set this db to the same as development or production.
  12 +test:
  13 + adapter: sqlite3
  14 + database: db/test.sqlite3
  15 + pool: 5
  16 + timeout: 5000
  17 +
  18 +production:
  19 + adapter: sqlite3
  20 + database: db/production.sqlite3
  21 + pool: 5
  22 + timeout: 5000
42 episode-194/todo/config/environment.rb
... ... @@ -0,0 +1,42 @@
  1 +# Be sure to restart your server when you modify this file
  2 +
  3 +# Specifies gem version of Rails to use when vendor/rails is not present
  4 +RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
  5 +
  6 +# Bootstrap the Rails environment, frameworks, and default configuration
  7 +require File.join(File.dirname(__FILE__), 'boot')
  8 +
  9 +Rails::Initializer.run do |config|
  10 + # Settings in config/environments/* take precedence over those specified here.
  11 + # Application configuration should go into files in config/initializers
  12 + # -- all .rb files in that directory are automatically loaded.
  13 +
  14 + # Add additional load paths for your own custom dirs
  15 + # config.load_paths += %W( #{RAILS_ROOT}/extras )
  16 +
  17 + # Specify gems that this application depends on and have them installed with rake gems:install
  18 + # config.gem "bj"
  19 + # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
  20 + # config.gem "sqlite3-ruby", :lib => "sqlite3"
  21 + # config.gem "aws-s3", :lib => "aws/s3"
  22 + config.gem "mongo_mapper"
  23 +
  24 + # Only load the plugins named here, in the order given (default is alphabetical).
  25 + # :all can be used as a placeholder for all plugins not explicitly named
  26 + # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
  27 +
  28 + # Skip frameworks you're not going to use. To use Rails without a database,
  29 + # you must remove the Active Record framework.
  30 + # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
  31 +
  32 + # Activate observers that should always be running
  33 + # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
  34 +
  35 + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
  36 + # Run "rake -D time" for a list of tasks for finding time zone names.
  37 + config.time_zone = 'UTC'
  38 +
  39 + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
  40 + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
  41 + # config.i18n.default_locale = :de
  42 +end
17 episode-194/todo/config/environments/development.rb
... ... @@ -0,0 +1,17 @@
  1 +# Settings specified here will take precedence over those in config/environment.rb
  2 +
  3 +# In the development environment your application's code is reloaded on
  4 +# every request. This slows down response time but is perfect for development
  5 +# since you don't have to restart the webserver when you make code changes.
  6 +config.cache_classes = false
  7 +
  8 +# Log error messages when you accidentally call methods on nil.
  9 +config.whiny_nils = true
  10 +
  11 +# Show full error reports and disable caching
  12 +config.action_controller.consider_all_requests_local = true
  13 +config.action_view.debug_rjs = true
  14 +config.action_controller.perform_caching = false
  15 +
  16 +# Don't care if the mailer can't send
  17 +config.action_mailer.raise_delivery_errors = false
28 episode-194/todo/config/environments/production.rb
... ... @@ -0,0 +1,28 @@
  1 +# Settings specified here will take precedence over those in config/environment.rb
  2 +
  3 +# The production environment is meant for finished, "live" apps.
  4 +# Code is not reloaded between requests
  5 +config.cache_classes = true
  6 +
  7 +# Full error reports are disabled and caching is turned on
  8 +config.action_controller.consider_all_requests_local = false
  9 +config.action_controller.perform_caching = true
  10 +config.action_view.cache_template_loading = true
  11 +
  12 +# See everything in the log (default is :info)
  13 +# config.log_level = :debug
  14 +
  15 +# Use a different logger for distributed setups
  16 +# config.logger = SyslogLogger.new
  17 +
  18 +# Use a different cache store in production
  19 +# config.cache_store = :mem_cache_store
  20 +
  21 +# Enable serving of images, stylesheets, and javascripts from an asset server
  22 +# config.action_controller.asset_host = "http://assets.example.com"
  23 +
  24 +# Disable delivery errors, bad email addresses will be ignored
  25 +# config.action_mailer.raise_delivery_errors = false
  26 +
  27 +# Enable threaded mode
  28 +# config.threadsafe!
28 episode-194/todo/config/environments/test.rb
... ... @@ -0,0 +1,28 @@
  1 +# Settings specified here will take precedence over those in config/environment.rb
  2 +
  3 +# The test environment is used exclusively to run your application's
  4 +# test suite. You never need to work with it otherwise. Remember that
  5 +# your test database is "scratch space" for the test suite and is wiped
  6 +# and recreated between test runs. Don't rely on the data there!
  7 +config.cache_classes = true
  8 +
  9 +# Log error messages when you accidentally call methods on nil.
  10 +config.whiny_nils = true
  11 +
  12 +# Show full error reports and disable caching
  13 +config.action_controller.consider_all_requests_local = true
  14 +config.action_controller.perform_caching = false
  15 +config.action_view.cache_template_loading = true
  16 +
  17 +# Disable request forgery protection in test environment
  18 +config.action_controller.allow_forgery_protection = false
  19 +
  20 +# Tell Action Mailer not to deliver emails to the real world.
  21 +# The :test delivery method accumulates sent emails in the
  22 +# ActionMailer::Base.deliveries array.
  23 +config.action_mailer.delivery_method = :test
  24 +
  25 +# Use SQL instead of Active Record's schema dumper when creating the test database.
  26 +# This is necessary if your schema can't be completely dumped by the schema dumper,
  27 +# like if you have constraints or database-specific column types
  28 +# config.active_record.schema_format = :sql
7 episode-194/todo/config/initializers/backtrace_silencers.rb
... ... @@ -0,0 +1,7 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
  4 +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
  5 +
  6 +# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
  7 +# Rails.backtrace_cleaner.remove_silencers!
10 episode-194/todo/config/initializers/inflections.rb
... ... @@ -0,0 +1,10 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# Add new inflection rules using the following format
  4 +# (all these examples are active by default):
  5 +# ActiveSupport::Inflector.inflections do |inflect|
  6 +# inflect.plural /^(ox)$/i, '\1en'
  7 +# inflect.singular /^(ox)en/i, '\1'
  8 +# inflect.irregular 'person', 'people'
  9 +# inflect.uncountable %w( fish sheep )
  10 +# end
5 episode-194/todo/config/initializers/mime_types.rb
... ... @@ -0,0 +1,5 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# Add new mime types for use in respond_to blocks:
  4 +# Mime::Type.register "text/richtext", :rtf
  5 +# Mime::Type.register_alias "text/html", :iphone
1  episode-194/todo/config/initializers/mongo_config.rb
... ... @@ -0,0 +1 @@
  1 +MongoMapper.database = "todo-#{Rails.env}"
21 episode-194/todo/config/initializers/new_rails_defaults.rb
... ... @@ -0,0 +1,21 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# These settings change the behavior of Rails 2 apps and will be defaults
  4 +# for Rails 3. You can remove this initializer when Rails 3 is released.
  5 +
  6 +if defined?(ActiveRecord)
  7 + # Include Active Record class name as root for JSON serialized output.
  8 + ActiveRecord::Base.include_root_in_json = true
  9 +
  10 + # Store the full class name (including module namespace) in STI type column.
  11 + ActiveRecord::Base.store_full_sti_class = true
  12 +end
  13 +
  14 +ActionController::Routing.generate_best_match = false
  15 +
  16 +# Use ISO 8601 format for JSON serialized times and dates.
  17 +ActiveSupport.use_standard_json_time_format = true
  18 +
  19 +# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
  20 +# if you're including raw json in an HTML page.
  21 +ActiveSupport.escape_html_entities_in_json = false
15 episode-194/todo/config/initializers/session_store.rb
... ... @@ -0,0 +1,15 @@
  1 +# Be sure to restart your server when you modify this file.
  2 +
  3 +# Your secret key for verifying cookie session data integrity.
  4 +# If you change this key, all old sessions will become invalid!
  5 +# Make sure the secret is at least 30 characters and all random,
  6 +# no regular words or you'll be exposed to dictionary attacks.
  7 +ActionController::Base.session = {
  8 + :key => '_todo_session',
  9 + :secret => '185c738aa934b158f8baaa8215e401c89e92a7f92121b35da82eb2b6dcabc915182ab027e8f95dd52e83b7aad4e6dd432ee7d5e5e05cafd3741a11caaf010fc4'
  10 +}
  11 +
  12 +# Use the database for sessions instead of the cookie-based default,
  13 +# which shouldn't be used to store highly confidential information
  14 +# (create the session table with "rake db:sessions:create")
  15 +# ActionController::Base.session_store = :active_record_store
5 episode-194/todo/config/locales/en.yml
... ... @@ -0,0 +1,5 @@
  1 +# Sample localization file for English. Add more files in this directory for other locales.
  2 +# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
  3 +
  4 +en:
  5 + hello: "Hello world"
5 episode-194/todo/config/routes.rb
... ... @@ -0,0 +1,5 @@
  1 +ActionController::Routing::Routes.draw do |map|
  2 + map.resources :tasks
  3 + map.resources :projects
  4 + map.root :projects
  5 +end
0  episode-194/todo/db/development.sqlite3
No changes.
7 episode-194/todo/db/seeds.rb
... ... @@ -0,0 +1,7 @@
  1 +# This file should contain all the record creation needed to seed the database with its default values.
  2 +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
  3 +#
  4 +# Examples:
  5 +#
  6 +# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
  7 +# Major.create(:name => 'Daley', :city => cities.first)
2  episode-194/todo/doc/README_FOR_APP
... ... @@ -0,0 +1,2 @@
  1 +Use this README file to introduce your application and point to useful places in the API for learning more.
  2 +Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
30 episode-194/todo/public/404.html
... ... @@ -0,0 +1,30 @@
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3 +
  4 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5 +
  6 +<head>
  7 + <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  8 + <title>The page you were looking for doesn't exist (404)</title>
  9 + <style type="text/css">
  10 + body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
  11 + div.dialog {
  12 + width: 25em;
  13 + padding: 0 4em;
  14 + margin: 4em auto 0 auto;
  15 + border: 1px solid #ccc;
  16 + border-right-color: #999;
  17 + border-bottom-color: #999;
  18 + }
  19 + h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
  20 + </style>
  21 +</head>
  22 +
  23 +<body>
  24 + <!-- This file lives in public/404.html -->
  25 + <div class="dialog">
  26 + <h1>The page you were looking for doesn't exist.</h1>
  27 + <p>You may have mistyped the address or the page may have moved.</p>
  28 + </div>
  29 +</body>
  30 +</html>
30 episode-194/todo/public/422.html
... ... @@ -0,0 +1,30 @@
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3 +
  4 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5 +
  6 +<head>
  7 + <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  8 + <title>The change you wanted was rejected (422)</title>
  9 + <style type="text/css">
  10 + body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
  11 + div.dialog {
  12 + width: 25em;
  13 + padding: 0 4em;
  14 + margin: 4em auto 0 auto;
  15 + border: 1px solid #ccc;
  16 + border-right-color: #999;
  17 + border-bottom-color: #999;
  18 + }
  19 + h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
  20 + </style>
  21 +</head>
  22 +
  23 +<body>
  24 + <!-- This file lives in public/422.html -->
  25 + <div class="dialog">
  26 + <h1>The change you wanted was rejected.</h1>
  27 + <p>Maybe you tried to change something you didn't have access to.</p>
  28 + </div>
  29 +</body>
  30 +</html>
30 episode-194/todo/public/500.html
... ... @@ -0,0 +1,30 @@
  1 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3 +
  4 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5 +
  6 +<head>
  7 + <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  8 + <title>We're sorry, but something went wrong (500)</title>
  9 + <style type="text/css">
  10 + body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
  11 + div.dialog {
  12 + width: 25em;
  13 + padding: 0 4em;
  14 + margin: 4em auto 0 auto;
  15 + border: 1px solid #ccc;
  16 + border-right-color: #999;
  17 + border-bottom-color: #999;
  18 + }
  19 + h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
  20 + </style>
  21 +</head>
  22 +
  23 +<body>
  24 + <!-- This file lives in public/500.html -->
  25 + <div class="dialog">
  26 + <h1>We're sorry, but something went wrong.</h1>
  27 + <p>We've been notified about this issue and we'll take a look at it shortly.</p>
  28 + </div>
  29 +</body>
  30 +</html>
0  episode-194/todo/public/favicon.ico
No changes.
BIN  episode-194/todo/public/images/rails.png
2  episode-194/todo/public/javascripts/application.js
... ... @@ -0,0 +1,2 @@
  1 +// Place your application-specific JavaScript functions and classes here
  2 +// This file is automatically included by javascript_include_tag :defaults
963 episode-194/todo/public/javascripts/controls.js
... ... @@ -0,0 +1,963 @@
  1 +// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
  2 +// (c) 2005-2008 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
  3 +// (c) 2005-2008 Jon Tirsen (http://www.tirsen.com)
  4 +// Contributors:
  5 +// Richard Livsey
  6 +// Rahul Bhargava
  7 +// Rob Wills
  8 +//
  9 +// script.aculo.us is freely distributable under the terms of an MIT-style license.
  10 +// For details, see the script.aculo.us web site: http://script.aculo.us/
  11 +
  12 +// Autocompleter.Base handles all the autocompletion functionality
  13 +// that's independent of the data source for autocompletion. This
  14 +// includes drawing the autocompletion menu, observing keyboard
  15 +// and mouse events, and similar.
  16 +//
  17 +// Specific autocompleters need to provide, at the very least,
  18 +// a getUpdatedChoices function that will be invoked every time
  19 +// the text inside the monitored textbox changes. This method
  20 +// should get the text for which to provide autocompletion by
  21 +// invoking this.getToken(), NOT by directly accessing
  22 +// this.element.value. This is to allow incremental tokenized
  23 +// autocompletion. Specific auto-completion logic (AJAX, etc)
  24 +// belongs in getUpdatedChoices.
  25 +//
  26 +// Tokenized incremental autocompletion is enabled automatically
  27 +// when an autocompleter is instantiated with the 'tokens' option
  28 +// in the options parameter, e.g.:
  29 +// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
  30 +// will incrementally autocomplete with a comma as the token.
  31 +// Additionally, ',' in the above example can be replaced with
  32 +// a token array, e.g. { tokens: [',', '\n'] } which
  33 +// enables autocompletion on multiple tokens. This is most
  34 +// useful when one of the tokens is \n (a newline), as it
  35 +// allows smart autocompletion after linebreaks.
  36 +
  37 +if(typeof Effect == 'undefined')
  38 + throw("controls.js requires including script.aculo.us' effects.js library");
  39 +
  40 +var Autocompleter = { };
  41 +Autocompleter.Base = Class.create({
  42 + baseInitialize: function(element, update, options) {
  43 + element = $(element);
  44 + this.element = element;
  45 + this.update = $(update);
  46 + this.hasFocus = false;
  47 + this.changed = false;
  48 + this.active = false;
  49 + this.index = 0;
  50 + this.entryCount = 0;
  51 + this.oldElementValue = this.element.value;
  52 +
  53 + if(this.setOptions)
  54 + this.setOptions(options);
  55 + else
  56 + this.options = options || { };
  57 +
  58 + this.options.paramName = this.options.paramName || this.element.name;
  59 + this.options.tokens = this.options.tokens || [];
  60 + this.options.frequency = this.options.frequency || 0.4;
  61 + this.options.minChars = this.options.minChars || 1;
  62 + this.options.onShow = this.options.onShow ||
  63 + function(element, update){
  64 + if(!update.style.position || update.style.position=='absolute') {
  65 + update.style.position = 'absolute';
  66 + Position.clone(element, update, {
  67 + setHeight: false,
  68 + offsetTop: element.offsetHeight
  69 + });
  70 + }
  71 + Effect.Appear(update,{duration:0.15});
  72 + };
  73 + this.options.onHide = this.options.onHide ||
  74 + function(element, update){ new Effect.Fade(update,{duration:0.15}) };
  75 +
  76 + if(typeof(this.options.tokens) == 'string')
  77 + this.options.tokens = new Array(this.options.tokens);
  78 + // Force carriage returns as token delimiters anyway
  79 + if (!this.options.tokens.include('\n'))
  80 + this.options.tokens.push('\n');
  81 +
  82 + this.observer = null;
  83 +
  84 + this.element.setAttribute('autocomplete','off');
  85 +
  86 + Element.hide(this.update);
  87 +
  88 + Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
  89 + Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
  90 + },
  91 +
  92 + show: function() {
  93 + if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
  94 + if(!this.iefix &&
  95 + (Prototype.Browser.IE) &&
  96 + (Element.getStyle(this.update, 'position')=='absolute')) {
  97 + new Insertion.After(this.update,
  98 + '<iframe id="' + this.update.id + '_iefix" '+
  99 + 'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
  100 + 'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
  101 + this.iefix = $(this.update.id+'_iefix');
  102 + }
  103 + if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
  104 + },
  105 +
  106 + fixIEOverlapping: function() {
  107 + Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
  108 + this.iefix.style.zIndex = 1;
  109 + this.update.style.zIndex = 2;
  110 + Element.show(this.iefix);
  111 + },
  112 +
  113 + hide: function() {
  114 + this.stopIndicator();
  115 + if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
  116 + if(this.iefix) Element.hide(this.iefix);
  117 + },
  118 +
  119 + startIndicator: function() {
  120 + if(this.options.indicator) Element.show(this.options.indicator);
  121 + },
  122 +
  123 + stopIndicator: function() {
  124 + if(this.options.indicator) Element.hide(this.options.indicator);
  125 + },
  126 +
  127 + onKeyPress: function(event) {
  128 + if(this.active)
  129 + switch(event.keyCode) {
  130 + case Event.KEY_TAB:
  131 + case Event.KEY_RETURN:
  132 + this.selectEntry();
  133 + Event.stop(event);
  134 + case Event.KEY_ESC:
  135 + this.hide();
  136 + this.active = false;
  137 + Event.stop(event);
  138 + return;
  139 + case Event.KEY_LEFT:
  140 + case Event.KEY_RIGHT:
  141 + return;
  142 + case Event.KEY_UP:
  143 + this.markPrevious();
  144 + this.render();
  145 + Event.stop(event);
  146 + return;
  147 + case Event.KEY_DOWN:
  148 + this.markNext();
  149 + this.render();
  150 + Event.stop(event);
  151 + return;
  152 + }
  153 + else
  154 + if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
  155 + (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
  156 +
  157 + this.changed = true;
  158 + this.hasFocus = true;
  159 +
  160 + if(this.observer) clearTimeout(this.observer);
  161 + this.observer =
  162 + setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
  163 + },
  164 +
  165 + activate: function() {
  166 + this.changed = false;
  167 + this.hasFocus = true;
  168 + this.getUpdatedChoices();
  169 + },
  170 +
  171 + onHover: function(event) {
  172 + var element = Event.findElement(event, 'LI');
  173 + if(this.index != element.autocompleteIndex)
  174 + {
  175 + this.index = element.autocompleteIndex;
  176 + this.render();
  177 + }
  178 + Event.stop(event);
  179 + },
  180 +
  181 + onClick: function(event) {
  182 + var element = Event.findElement(event, 'LI');
  183 + this.index = element.autocompleteIndex;
  184 + this.selectEntry();
  185 + this.hide();
  186 + },
  187 +
  188 + onBlur: function(event) {
  189 + // needed to make click events working
  190 + setTimeout(this.hide.bind(this), 250);
  191 + this.hasFocus = false;
  192 + this.active = false;
  193 + },
  194 +
  195 + render: function() {
  196 + if(this.entryCount > 0) {
  197 + for (var i = 0; i < this.entryCount; i++)
  198 + this.index==i ?
  199 + Element.addClassName(this.getEntry(i),"selected") :
  200 + Element.removeClassName(this.getEntry(i),"selected");
  201 + if(this.hasFocus) {
  202 + this.show();
  203 + this.active = true;
  204 + }
  205 + } else {
  206 + this.active = false;
  207 + this.hide();
  208 + }
  209 + },
  210 +
  211 + markPrevious: function() {
  212 + if(this.index > 0) this.index--;
  213 + else this.index = this.entryCount-1;
  214 + this.getEntry(this.index).scrollIntoView(true);
  215 + },
  216 +
  217 + markNext: function() {
  218 + if(this.index < this.entryCount-1) this.index++;
  219 + else this.index = 0;
  220 + this.getEntry(this.index).scrollIntoView(false);
  221 + },
  222 +
  223 + getEntry: function(index) {
  224 + return this.update.firstChild.childNodes[index];
  225 + },
  226 +
  227 + getCurrentEntry: function() {
  228 + return this.getEntry(this.index);
  229 + },
  230 +
  231 + selectEntry: function() {
  232 + this.active = false;
  233 + this.updateElement(this.getCurrentEntry());
  234 + },
  235 +
  236 + updateElement: function(selectedElement) {
  237 + if (this.options.updateElement) {
  238 + this.opt