Permalink
Browse files

adding episode 209

  • Loading branch information...
1 parent 6d6471d commit ece998dc5d1ead9f2149687bc4ca02eadc699d10 @ryanb committed Apr 12, 2010
Showing with 9,149 additions and 0 deletions.
  1. +11 −0 episode-209/README
  2. +4 −0 episode-209/todo/.gitignore
  3. +27 −0 episode-209/todo/Gemfile
  4. +1 −0 episode-209/todo/README
  5. +10 −0 episode-209/todo/Rakefile
  6. +15 −0 episode-209/todo/app/controllers/application_controller.rb
  7. +44 −0 episode-209/todo/app/controllers/projects_controller.rb
  8. +36 −0 episode-209/todo/app/controllers/tasks_controller.rb
  9. +3 −0 episode-209/todo/app/helpers/application_helper.rb
  10. +23 −0 episode-209/todo/app/helpers/layout_helper.rb
  11. +2 −0 episode-209/todo/app/helpers/projects_helper.rb
  12. +2 −0 episode-209/todo/app/helpers/tasks_helper.rb
  13. +3 −0 episode-209/todo/app/models/project.rb
  14. +3 −0 episode-209/todo/app/models/task.rb
  15. +9 −0 episode-209/todo/app/models/user.rb
  16. +33 −0 episode-209/todo/app/views/layouts/application.html.erb
  17. +8 −0 episode-209/todo/app/views/projects/_form.html.erb
  18. +8 −0 episode-209/todo/app/views/projects/edit.html.erb
  19. +16 −0 episode-209/todo/app/views/projects/index.html.erb
  20. +5 −0 episode-209/todo/app/views/projects/new.html.erb
  21. +17 −0 episode-209/todo/app/views/projects/show.html.erb
  22. +13 −0 episode-209/todo/app/views/tasks/_form.html.erb
  23. +4 −0 episode-209/todo/app/views/tasks/edit.html.erb
  24. +4 −0 episode-209/todo/app/views/tasks/new.html.erb
  25. +4 −0 episode-209/todo/config.ru
  26. +44 −0 episode-209/todo/config/application.rb
  27. +14 −0 episode-209/todo/config/boot.rb
  28. +22 −0 episode-209/todo/config/database.yml
  29. +5 −0 episode-209/todo/config/environment.rb
  30. +21 −0 episode-209/todo/config/environments/development.rb
  31. +42 −0 episode-209/todo/config/environments/production.rb
  32. +29 −0 episode-209/todo/config/environments/test.rb
  33. +7 −0 episode-209/todo/config/initializers/backtrace_silencers.rb
  34. +6 −0 episode-209/todo/config/initializers/cookie_verification_secret.rb
  35. +116 −0 episode-209/todo/config/initializers/devise.rb
  36. +10 −0 episode-209/todo/config/initializers/inflections.rb
  37. +5 −0 episode-209/todo/config/initializers/mime_types.rb
  38. +10 −0 episode-209/todo/config/initializers/session_store.rb
  39. +36 −0 episode-209/todo/config/locales/devise.en.yml
  40. +5 −0 episode-209/todo/config/locales/en.yml
  41. +63 −0 episode-209/todo/config/routes.rb
  42. +13 −0 episode-209/todo/db/migrate/20100412041830_create_projects.rb
  43. +15 −0 episode-209/todo/db/migrate/20100412041924_create_tasks.rb
  44. +23 −0 episode-209/todo/db/migrate/20100412062912_devise_create_users.rb
  45. +47 −0 episode-209/todo/db/schema.rb
  46. +7 −0 episode-209/todo/db/seeds.rb
  47. +2 −0 episode-209/todo/doc/README_FOR_APP
  48. +1 −0 episode-209/todo/lib/generators
  49. 0 episode-209/todo/lib/tasks/.gitkeep
  50. +26 −0 episode-209/todo/public/404.html
  51. +26 −0 episode-209/todo/public/422.html
  52. +26 −0 episode-209/todo/public/500.html
  53. 0 episode-209/todo/public/favicon.ico
  54. +2 −0 episode-209/todo/public/javascripts/application.js
  55. +965 −0 episode-209/todo/public/javascripts/controls.js
  56. +974 −0 episode-209/todo/public/javascripts/dragdrop.js
  57. +1,123 −0 episode-209/todo/public/javascripts/effects.js
  58. +4,874 −0 episode-209/todo/public/javascripts/prototype.js
  59. +109 −0 episode-209/todo/public/javascripts/rails.js
  60. +5 −0 episode-209/todo/public/robots.txt
  61. 0 episode-209/todo/public/stylesheets/.gitkeep
  62. +87 −0 episode-209/todo/public/stylesheets/application.css
  63. +9 −0 episode-209/todo/script/rails
  64. +7 −0 episode-209/todo/test/fixtures/projects.yml
  65. +11 −0 episode-209/todo/test/fixtures/tasks.yml
  66. +11 −0 episode-209/todo/test/fixtures/users.yml
  67. +9 −0 episode-209/todo/test/performance/browsing_test.rb
  68. +13 −0 episode-209/todo/test/test_helper.rb
  69. +8 −0 episode-209/todo/test/unit/project_test.rb
  70. +8 −0 episode-209/todo/test/unit/task_test.rb
  71. +8 −0 episode-209/todo/test/unit/user_test.rb
  72. 0 episode-209/todo/vendor/plugins/.gitkeep
View
@@ -0,0 +1,11 @@
+Railscasts Episode #209: Introducing Devise
+
+http://railscasts.com/episodes/209
+
+Commands
+
+ bundle install
+ rails generate devise_install
+ rails generate devise User
+ rake db:migrate
+ rake routes
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
View
@@ -0,0 +1,27 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.0.beta2'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'sqlite3-ruby', :require => 'sqlite3'
+gem 'devise', '1.1.rc0'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri', '1.4.1'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for certain environments:
+# gem 'rspec', :group => :test
+# group :test do
+# gem 'webrat'
+# end
View
@@ -0,0 +1 @@
+Example rails application used in 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,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 => '9ae178eac1fbbd4062a93c8c558a12ef'
+
+ # 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 ProjectsController < ApplicationController
+ def index
+ @projects = Project.find(:all)
+ end
+
+ def show
+ @project = Project.find(params[:id])
+ end
+
+ def new
+ @project = Project.new
+ end
+
+ def create
+ @project = Project.new(params[:project])
+ if @project.save
+ flash[:notice] = "Successfully created project."
+ redirect_to @project
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @project = Project.find(params[:id])
+ end
+
+ def update
+ @project = Project.find(params[:id])
+ if @project.update_attributes(params[:project])
+ flash[:notice] = "Successfully updated project."
+ redirect_to @project
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @project = Project.find(params[:id])
+ @project.destroy
+ flash[:notice] = "Successfully destroyed project."
+ redirect_to projects_url
+ end
+end
@@ -0,0 +1,36 @@
+class TasksController < ApplicationController
+ def new
+ @task = Task.new(:project_id => params[:project_id])
+ end
+
+ def create
+ @task = Task.new(params[:task])
+ if @task.save
+ flash[:notice] = "Successfully created task."
+ redirect_to @task.project
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @task = Task.find(params[:id])
+ end
+
+ def update
+ @task = Task.find(params[:id])
+ if @task.update_attributes(params[:task])
+ flash[:notice] = "Successfully updated task."
+ redirect_to @task.project
+ else
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ @task = Task.find(params[:id])
+ @task.destroy
+ flash[:notice] = "Successfully destroyed task."
+ redirect_to @task.project
+ 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,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 ProjectsHelper
+end
@@ -0,0 +1,2 @@
+module TasksHelper
+end
@@ -0,0 +1,3 @@
+class Project < ActiveRecord::Base
+ has_many :tasks
+end
@@ -0,0 +1,3 @@
+class Task < ActiveRecord::Base
+ belongs_to :project
+end
@@ -0,0 +1,9 @@
+class User < ActiveRecord::Base
+ # Include default devise modules. Others available are:
+ # :token_authenticatable, :lockable, :timeoutable, :confirmable and :activatable
+ devise :database_authenticatable, :registerable,
+ :recoverable, :rememberable, :trackable, :validatable
+
+ # Setup accessible (or protected) attributes for your model
+ attr_accessible :email, :password, :password_confirmation
+end
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title><%= yield(:title) || "Untitled" %></title>
+ <%= stylesheet_link_tag 'application' %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <div id="user_nav">
+ <% if user_signed_in? %>
+ Signed in as <%= current_user.email %>. Not you?
+ <%= link_to "Sign out", destroy_user_session_path %>
+ <% else %>
+ <%= link_to "Sign up", new_user_registration_path %> or <%= link_to "sign in", new_user_session_path %>
+ <% end %>
+ </div>
+
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+
+ <% if show_title? %>
+ <h1><%= yield(:title) %></h1>
+ <% end %>
+
+ <%= yield %>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,8 @@
+<%= error_messages_for :project %>
+<%= form_for @project do |f| %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p><%= f.submit %></p>
+<% end %>
@@ -0,0 +1,8 @@
+<% title "Edit Project" %>
+
+<%= render :partial => 'form' %>
+
+<p>
+ <%= link_to "Show", @project %> |
+ <%= link_to "View All", projects_path %>
+</p>
@@ -0,0 +1,16 @@
+<% title "Projects" %>
+
+<table>
+ <tr>
+ <th>Name</th>
+ </tr>
+ <% for project in @projects %>
+ <tr>
+ <td><%= link_to project.name, project %></td>
+ <td><%= link_to "Edit", edit_project_path(project) %></td>
+ <td><%= link_to "Destroy", project, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+ <% end %>
+</table>
+
+<p><%= link_to "New Project", new_project_path %></p>
@@ -0,0 +1,5 @@
+<% title "New Project" %>
+
+<%= render :partial => 'form' %>
+
+<p><%= link_to "Back to List", projects_path %></p>
@@ -0,0 +1,17 @@
+<% title @project.name %>
+
+<h2>Tasks</h2>
+<ul>
+ <% for task in @project.tasks %>
+ <li>
+ <%= task.name %>
+ (<%= link_to "Edit", edit_task_path(task) %> |
+ <%= link_to "Destroy", task, :confirm => "Are you sure?", :method => :delete %>)
+ </li>
+ <% end %>
+</ul>
+
+<p>
+ <%= link_to "New Task", new_task_path(:project_id => @project) %> |
+ <%= link_to "View All Projects", projects_path %>
+</p>
@@ -0,0 +1,13 @@
+<%= error_messages_for :task %>
+<%= form_for @task do |f| %>
+ <%= f.hidden_field :project_id %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :completed_at %><br />
+ <%= f.date_select :completed_at %>
+ </p>
+ <p><%= f.submit %></p>
+<% end %>
@@ -0,0 +1,4 @@
+<% title "Edit Task" %>
+
+<%= render :partial => 'form' %>
+
@@ -0,0 +1,4 @@
+<% title "New Task" %>
+
+<%= render :partial => 'form' %>
+
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Todo::Application
@@ -0,0 +1,44 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module Todo
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Add additional load paths for your own custom dirs
+ # config.load_paths += %W( #{config.root}/extras )
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # Configure generators values. Many other options are available, be sure to check the documentation.
+ # config.generators do |g|
+ # g.orm :active_record
+ # g.template_engine :erb
+ # g.test_framework :test_unit, :fixture => true
+ # end
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters << :password
+ config.cookie_secret = '980734b832ad1ba050aeba757e50dcddd47e6a137eaa23286234f6a81504a8fdc818fcbf564ceceb01c2154add61930807a17b8876dfed5c6da98217627202a1'
+ end
+end
@@ -0,0 +1,14 @@
+# Use locked gems if present.
+begin
+ require File.expand_path('../../.bundle/environment', __FILE__)
+
+rescue LoadError
+ # Otherwise, use RubyGems.
+ require 'rubygems'
+
+ # And set up the gems listed in the Gemfile.
+ if File.exist?(File.expand_path('../../Gemfile', __FILE__))
+ require 'bundler'
+ Bundler.setup
+ end
+end
Oops, something went wrong.

0 comments on commit ece998d

Please sign in to comment.