Permalink
Browse files

adding episode 178

  • Loading branch information...
1 parent c7bf4d5 commit a1e097d46ba10560ea3e4d67040514eb9dcf020b @ryanb committed Sep 7, 2009
Showing with 13,799 additions and 0 deletions.
  1. +9 −0 episode-178/README
  2. +4 −0 episode-178/todo/.gitignore
  3. +4 −0 episode-178/todo/README
  4. +10 −0 episode-178/todo/Rakefile
  5. +16 −0 episode-178/todo/app/controllers/application_controller.rb
  6. +46 −0 episode-178/todo/app/controllers/projects_controller.rb
  7. +43 −0 episode-178/todo/app/controllers/tasks_controller.rb
  8. +22 −0 episode-178/todo/app/controllers/user_sessions_controller.rb
  9. +15 −0 episode-178/todo/app/controllers/users_controller.rb
  10. +3 −0 episode-178/todo/app/helpers/application_helper.rb
  11. +23 −0 episode-178/todo/app/helpers/layout_helper.rb
  12. +2 −0 episode-178/todo/app/helpers/projects_helper.rb
  13. +2 −0 episode-178/todo/app/helpers/tasks_helper.rb
  14. +2 −0 episode-178/todo/app/helpers/user_sessions_helper.rb
  15. +2 −0 episode-178/todo/app/helpers/users_helper.rb
  16. +7 −0 episode-178/todo/app/models/project.rb
  17. +4 −0 episode-178/todo/app/models/task.rb
  18. +4 −0 episode-178/todo/app/models/user.rb
  19. +2 −0 episode-178/todo/app/models/user_session.rb
  20. +32 −0 episode-178/todo/app/views/layouts/application.html.erb
  21. +12 −0 episode-178/todo/app/views/projects/_form.html.erb
  22. +8 −0 episode-178/todo/app/views/projects/edit.html.erb
  23. +27 −0 episode-178/todo/app/views/projects/index.html.erb
  24. +5 −0 episode-178/todo/app/views/projects/new.html.erb
  25. +19 −0 episode-178/todo/app/views/projects/show.html.erb
  26. +12 −0 episode-178/todo/app/views/tasks/_form.html.erb
  27. +4 −0 episode-178/todo/app/views/tasks/edit.html.erb
  28. +4 −0 episode-178/todo/app/views/tasks/new.html.erb
  29. +16 −0 episode-178/todo/app/views/user_sessions/new.html.erb
  30. +24 −0 episode-178/todo/app/views/users/new.html.erb
  31. +110 −0 episode-178/todo/config/boot.rb
  32. +19 −0 episode-178/todo/config/database.yml
  33. +68 −0 episode-178/todo/config/environment.rb
  34. +17 −0 episode-178/todo/config/environments/development.rb
  35. +22 −0 episode-178/todo/config/environments/production.rb
  36. +22 −0 episode-178/todo/config/environments/test.rb
  37. +10 −0 episode-178/todo/config/initializers/inflections.rb
  38. +5 −0 episode-178/todo/config/initializers/mime_types.rb
  39. +15 −0 episode-178/todo/config/initializers/new_rails_defaults.rb
  40. +11 −0 episode-178/todo/config/routes.rb
  41. +12 −0 episode-178/todo/db/migrate/20080823221824_create_projects.rb
  42. +14 −0 episode-178/todo/db/migrate/20080823223136_create_tasks.rb
  43. +16 −0 episode-178/todo/db/migrate/20090906214105_create_users.rb
  44. +15 −0 episode-178/todo/db/migrate/20090906215606_add_attachments_photo_to_project.rb
  45. +9 −0 episode-178/todo/db/migrate/20090906220012_add_user_id_to_projects.rb
  46. +43 −0 episode-178/todo/db/schema.rb
  47. +2 −0 episode-178/todo/doc/README_FOR_APP
  48. +54 −0 episode-178/todo/lib/authentication.rb
  49. +22 −0 episode-178/todo/lib/tasks/application.rake
  50. 0 episode-178/todo/log/.gitignore
  51. +30 −0 episode-178/todo/public/404.html
  52. +30 −0 episode-178/todo/public/422.html
  53. +30 −0 episode-178/todo/public/500.html
  54. +10 −0 episode-178/todo/public/dispatch.cgi
  55. +24 −0 episode-178/todo/public/dispatch.fcgi
  56. +10 −0 episode-178/todo/public/dispatch.rb
  57. 0 episode-178/todo/public/favicon.ico
  58. +2 −0 episode-178/todo/public/javascripts/application.js
  59. +963 −0 episode-178/todo/public/javascripts/controls.js
  60. +973 −0 episode-178/todo/public/javascripts/dragdrop.js
  61. +1,128 −0 episode-178/todo/public/javascripts/effects.js
  62. +4,320 −0 episode-178/todo/public/javascripts/prototype.js
  63. +5 −0 episode-178/todo/public/robots.txt
  64. +89 −0 episode-178/todo/public/stylesheets/application.css
  65. +3 −0 episode-178/todo/script/about
  66. +3 −0 episode-178/todo/script/console
  67. +3 −0 episode-178/todo/script/dbconsole
  68. +3 −0 episode-178/todo/script/destroy
  69. +3 −0 episode-178/todo/script/generate
  70. +3 −0 episode-178/todo/script/performance/benchmarker
  71. +3 −0 episode-178/todo/script/performance/profiler
  72. +3 −0 episode-178/todo/script/performance/request
  73. +3 −0 episode-178/todo/script/plugin
  74. +3 −0 episode-178/todo/script/process/inspector
  75. +3 −0 episode-178/todo/script/process/reaper
  76. +3 −0 episode-178/todo/script/process/spawner
  77. +3 −0 episode-178/todo/script/runner
  78. +3 −0 episode-178/todo/script/server
  79. +5 −0 episode-178/todo/test/fixtures/projects.yml
  80. +9 −0 episode-178/todo/test/fixtures/tasks.yml
  81. +14 −0 episode-178/todo/test/fixtures/users.yml
  82. +54 −0 episode-178/todo/test/functional/projects_controller_test.rb
  83. +44 −0 episode-178/todo/test/functional/tasks_controller_test.rb
  84. +20 −0 episode-178/todo/test/functional/user_sessions_controller_test.rb
  85. +20 −0 episode-178/todo/test/functional/users_controller_test.rb
  86. +38 −0 episode-178/todo/test/test_helper.rb
  87. +7 −0 episode-178/todo/test/unit/project_test.rb
  88. +7 −0 episode-178/todo/test/unit/task_test.rb
  89. +4 −0 episode-178/todo/test/unit/user_test.rb
  90. 0 episode-178/todo/tmp/.gitignore
  91. 0 episode-178/todo/tmp/restart.txt
  92. +26 −0 episode-178/todo/vendor/plugins/paperclip/LICENSE
  93. +174 −0 episode-178/todo/vendor/plugins/paperclip/README.rdoc
  94. +99 −0 episode-178/todo/vendor/plugins/paperclip/Rakefile
  95. +6 −0 episode-178/todo/vendor/plugins/paperclip/cucumber/paperclip_steps.rb
  96. +5 −0 episode-178/todo/vendor/plugins/paperclip/generators/paperclip/USAGE
  97. +27 −0 episode-178/todo/vendor/plugins/paperclip/generators/paperclip/paperclip_generator.rb
  98. +19 −0 episode-178/todo/vendor/plugins/paperclip/generators/paperclip/templates/paperclip_migration.rb.erb
  99. +1 −0 episode-178/todo/vendor/plugins/paperclip/init.rb
  100. +352 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip.rb
  101. +414 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/attachment.rb
  102. +33 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/callback_compatability.rb
  103. +115 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/geometry.rb
  104. +108 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/interpolations.rb
  105. +58 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/iostream.rb
  106. +4 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/matchers.rb
  107. +49 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/matchers/have_attached_file_matcher.rb
  108. +66 −0 .../todo/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb
  109. +48 −0 ...-178/todo/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_presence_matcher.rb
  110. +83 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/matchers/validate_attachment_size_matcher.rb
  111. +49 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/processor.rb
  112. +243 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/storage.rb
  113. +73 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/thumbnail.rb
  114. +48 −0 episode-178/todo/vendor/plugins/paperclip/lib/paperclip/upfile.rb
  115. +37 −0 episode-178/todo/vendor/plugins/paperclip/paperclip.gemspec
  116. +117 −0 episode-178/todo/vendor/plugins/paperclip/shoulda_macros/paperclip.rb
  117. +79 −0 episode-178/todo/vendor/plugins/paperclip/tasks/paperclip_tasks.rake
  118. +1 −0 episode-178/todo/vendor/plugins/paperclip/test/.gitignore
  119. +780 −0 episode-178/todo/vendor/plugins/paperclip/test/attachment_test.rb
  120. +4 −0 episode-178/todo/vendor/plugins/paperclip/test/database.yml
  121. BIN episode-178/todo/vendor/plugins/paperclip/test/fixtures/12k.png
  122. BIN episode-178/todo/vendor/plugins/paperclip/test/fixtures/50x50.png
  123. BIN episode-178/todo/vendor/plugins/paperclip/test/fixtures/5k.png
  124. +1 −0 episode-178/todo/vendor/plugins/paperclip/test/fixtures/bad.png
  125. +4 −0 episode-178/todo/vendor/plugins/paperclip/test/fixtures/s3.yml
  126. 0 episode-178/todo/vendor/plugins/paperclip/test/fixtures/text.txt
  127. BIN episode-178/todo/vendor/plugins/paperclip/test/fixtures/twopage.pdf
  128. +177 −0 episode-178/todo/vendor/plugins/paperclip/test/geometry_test.rb
  129. +108 −0 episode-178/todo/vendor/plugins/paperclip/test/helper.rb
  130. +483 −0 episode-178/todo/vendor/plugins/paperclip/test/integration_test.rb
  131. +124 −0 episode-178/todo/vendor/plugins/paperclip/test/interpolations_test.rb
  132. +71 −0 episode-178/todo/vendor/plugins/paperclip/test/iostream_test.rb
  133. +21 −0 episode-178/todo/vendor/plugins/paperclip/test/matchers/have_attached_file_matcher_test.rb
  134. +30 −0 ...-178/todo/vendor/plugins/paperclip/test/matchers/validate_attachment_content_type_matcher_test.rb
  135. +21 −0 episode-178/todo/vendor/plugins/paperclip/test/matchers/validate_attachment_presence_matcher_test.rb
  136. +50 −0 episode-178/todo/vendor/plugins/paperclip/test/matchers/validate_attachment_size_matcher_test.rb
  137. +327 −0 episode-178/todo/vendor/plugins/paperclip/test/paperclip_test.rb
  138. +10 −0 episode-178/todo/vendor/plugins/paperclip/test/processor_test.rb
  139. +280 −0 episode-178/todo/vendor/plugins/paperclip/test/storage_test.rb
  140. +227 −0 episode-178/todo/vendor/plugins/paperclip/test/thumbnail_test.rb
View
@@ -0,0 +1,9 @@
+Railscasts Episode #178: 7 Security Tips
+
+http://railscasts.com/episodes/178
+
+script/console
+
+ p = Project.find(2)
+ p.update_attributes(:task_ids => [4])
+ p.tasks
@@ -0,0 +1,4 @@
+tmp/**/*
+log/*.log
+*.sqlite3
+public/photos/**/*
View
@@ -0,0 +1,4 @@
+Railscasts Example To Do App
+--
+
+To setup the app, just run `rake setup`.
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,16 @@
+# 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
+ include Authentication
+ 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,46 @@
+class ProjectsController < ApplicationController
+ before_filter :login_required
+
+ def index
+ @projects = current_user.projects.all(:conditions => ["name like ?", "%#{params[:search]}%"])
+ end
+
+ def show
+ @project = current_user.projects.find(params[:id])
+ end
+
+ def new
+ @project = current_user.projects.build
+ end
+
+ def create
+ @project = current_user.projects.build(params[:project])
+ if @project.save
+ flash[:notice] = "Successfully created project."
+ redirect_to @project
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @project = current_user.projects.find(params[:id])
+ end
+
+ def update
+ @project = current_user.projects.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 = current_user.projects.find(params[:id])
+ @project.destroy
+ flash[:notice] = "Successfully destroyed project."
+ redirect_to projects_url
+ end
+end
@@ -0,0 +1,43 @@
+class TasksController < ApplicationController
+ before_filter :login_required
+
+ def new
+ @project = current_user.projects.find(params[:project_id])
+ @task = @project.tasks.build
+ end
+
+ def create
+ @project = current_user.projects.find(params[:project_id])
+ @task = @project.tasks.build(params[:task])
+ if @task.save
+ flash[:notice] = "Successfully created task."
+ redirect_to @task.project
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @project = current_user.projects.find(params[:project_id])
+ @task = @project.tasks.find(params[:id])
+ end
+
+ def update
+ @project = current_user.projects.find(params[:project_id])
+ @task = @project.tasks.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
+ @project = current_user.projects.find(params[:project_id])
+ @task = @project.tasks.find(params[:id])
+ @task.destroy
+ flash[:notice] = "Successfully destroyed task."
+ redirect_to @task.project
+ end
+end
@@ -0,0 +1,22 @@
+class UserSessionsController < ApplicationController
+ def new
+ @user_session = UserSession.new
+ end
+
+ def create
+ @user_session = UserSession.new(params[:user_session])
+ if @user_session.save
+ flash[:notice] = "Logged in successfully."
+ redirect_to_target_or_default(root_url)
+ else
+ render :action => 'new'
+ end
+ end
+
+ def destroy
+ @user_session = UserSession.find
+ @user_session.destroy
+ flash[:notice] = "You have been logged out."
+ redirect_to root_url
+ end
+end
@@ -0,0 +1,15 @@
+class UsersController < ApplicationController
+ def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new(params[:user])
+ if @user.save
+ flash[:notice] = "Thank you for signing up! You are now logged in."
+ redirect_to root_url
+ else
+ render :action => 'new'
+ end
+ 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,2 @@
+module UserSessionsHelper
+end
@@ -0,0 +1,2 @@
+module UsersHelper
+end
@@ -0,0 +1,7 @@
+class Project < ActiveRecord::Base
+ belongs_to :user
+ has_many :tasks
+ has_attached_file :photo
+ attr_accessible :name, :photo
+ validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']
+end
@@ -0,0 +1,4 @@
+class Task < ActiveRecord::Base
+ belongs_to :project
+ attr_accessible :name, :complete
+end
@@ -0,0 +1,4 @@
+class User < ActiveRecord::Base
+ acts_as_authentic
+ has_many :projects
+end
@@ -0,0 +1,2 @@
+class UserSession < Authlogic::Session::Base
+end
@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title><%= h(yield(:title) || "Untitled") %></title>
+ <%= stylesheet_link_tag 'application' %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <div id="user_nav">
+ <% if logged_in? %>
+ Welcome <%=h current_user.username %>! Not you?
+ <%= link_to "Log out", logout_path %>
+ <% else %>
+ <%= link_to "Sign up", signup_path %> or
+ <%= link_to "log in", login_path %>.
+ <% end %>
+ </div>
+
+ <%- 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,12 @@
+<% form_for @project, :html => { :multipart => true } do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.label :photo %><br />
+ <%= f.file_field :photo %>
+ </p>
+ <p><%= f.submit "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,27 @@
+<% title "Projects" %>
+
+<% form_tag projects_path, :method => 'get' do %>
+ <p>
+ <%= label_tag :search, "Search:" %>
+ <%= text_field_tag :search, params[:search] %>
+ </p>
+ <p>
+ <%= label_tag :search, "Sort:" %>
+ <%= select_tag :order, options_for_select([["Date Created", "created_at"], ["Name", "name"]], :selected => params[:order]) %>
+ </p>
+ <p>
+ <%= submit_tag "Search", :name => nil %>
+ </p>
+<% end %>
+
+<% for project in @projects %>
+<div class="project">
+ <h2><%= link_to h(project.name), project %></h2>
+ <p>
+ <%= link_to "Edit", edit_project_path(project) %> |
+ <%= link_to "Destroy", project, :confirm => 'Are you sure?', :method => :delete %>
+ </p>
+</div>
+<% end %>
+
+<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,19 @@
+<% title @project.name %>
+
+<%= image_tag @project.photo.url %>
+
+<h2>Tasks</h2>
+<ul>
+ <% for task in @project.tasks %>
+ <li>
+ <%=h task.name %>
+ (<%= link_to "Edit", edit_project_task_path(@project, task) %> |
+ <%= link_to "Destroy", [@project, task], :confirm => "Are you sure?", :method => :delete %>)
+ </li>
+ <% end %>
+</ul>
+
+<p>
+ <%= link_to "New Task", new_project_task_path(@project) %> |
+ <%= link_to "View All Projects", projects_path %>
+</p>
@@ -0,0 +1,12 @@
+<% form_for [@project, @task] do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </p>
+ <p>
+ <%= f.check_box :complete %>
+ <%= f.label :complete %>
+ </p>
+ <p><%= f.submit "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,16 @@
+<% title "Log in" %>
+
+<p>Don't have an account? <%= link_to "Sign up!", signup_path %></p>
+
+<% form_for @user_session do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :username %><br />
+ <%= f.text_field :username %>
+ </p>
+ <p>
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </p>
+ <p><%= f.submit "Log in" %></p>
+<% end %>
Oops, something went wrong.

0 comments on commit a1e097d

Please sign in to comment.