Permalink
Browse files

adding episode 206

  • Loading branch information...
1 parent 2c770e2 commit 7be4427c71566612f87145201fa5e6d40d26a2ca @ryanb committed Mar 21, 2010
Showing with 8,336 additions and 0 deletions.
  1. +12 −0 episode-206/README
  2. +4 −0 episode-206/mailit/.gitignore
  3. +26 −0 episode-206/mailit/Gemfile
  4. +1 −0 episode-206/mailit/README
  5. +10 −0 episode-206/mailit/Rakefile
  6. +3 −0 episode-206/mailit/app/controllers/application_controller.rb
  7. +85 −0 episode-206/mailit/app/controllers/users_controller.rb
  8. +2 −0 episode-206/mailit/app/helpers/application_helper.rb
  9. +2 −0 episode-206/mailit/app/helpers/users_helper.rb
  10. +9 −0 episode-206/mailit/app/mailers/user_mailer.rb
  11. +2 −0 episode-206/mailit/app/models/user.rb
  12. +16 −0 episode-206/mailit/app/views/layouts/users.html.erb
  13. +5 −0 episode-206/mailit/app/views/user_mailer/registration_confirmation.html.erb
  14. +5 −0 episode-206/mailit/app/views/user_mailer/registration_confirmation.text.erb
  15. +15 −0 episode-206/mailit/app/views/users/_form.html.erb
  16. +6 −0 episode-206/mailit/app/views/users/edit.html.erb
  17. +25 −0 episode-206/mailit/app/views/users/index.html.erb
  18. +5 −0 episode-206/mailit/app/views/users/new.html.erb
  19. +13 −0 episode-206/mailit/app/views/users/show.html.erb
  20. +4 −0 episode-206/mailit/config.ru
  21. +42 −0 episode-206/mailit/config/application.rb
  22. +17 −0 episode-206/mailit/config/boot.rb
  23. +22 −0 episode-206/mailit/config/database.yml
  24. +5 −0 episode-206/mailit/config/environment.rb
  25. +19 −0 episode-206/mailit/config/environments/development.rb
  26. +33 −0 episode-206/mailit/config/environments/production.rb
  27. +29 −0 episode-206/mailit/config/environments/test.rb
  28. +7 −0 episode-206/mailit/config/initializers/backtrace_silencers.rb
  29. +7 −0 episode-206/mailit/config/initializers/cookie_verification_secret.rb
  30. +10 −0 episode-206/mailit/config/initializers/inflections.rb
  31. +5 −0 episode-206/mailit/config/initializers/mime_types.rb
  32. +15 −0 episode-206/mailit/config/initializers/session_store.rb
  33. +12 −0 episode-206/mailit/config/initializers/setup_mail.rb
  34. +5 −0 episode-206/mailit/config/locales/en.yml
  35. +61 −0 episode-206/mailit/config/routes.rb
  36. +14 −0 episode-206/mailit/db/migrate/20100320235315_create_users.rb
  37. +21 −0 episode-206/mailit/db/schema.rb
  38. +7 −0 episode-206/mailit/db/seeds.rb
  39. +2 −0 episode-206/mailit/doc/README_FOR_APP
  40. +7 −0 episode-206/mailit/lib/development_mail_interceptor.rb
  41. 0 episode-206/mailit/lib/tasks/.gitkeep
  42. +26 −0 episode-206/mailit/public/404.html
  43. +26 −0 episode-206/mailit/public/422.html
  44. +26 −0 episode-206/mailit/public/500.html
  45. 0 episode-206/mailit/public/favicon.ico
  46. BIN episode-206/mailit/public/images/rails.png
  47. +2 −0 episode-206/mailit/public/javascripts/application.js
  48. +963 −0 episode-206/mailit/public/javascripts/controls.js
  49. +973 −0 episode-206/mailit/public/javascripts/dragdrop.js
  50. +1,128 −0 episode-206/mailit/public/javascripts/effects.js
  51. +4,320 −0 episode-206/mailit/public/javascripts/prototype.js
  52. +110 −0 episode-206/mailit/public/javascripts/rails.js
  53. +5 −0 episode-206/mailit/public/robots.txt
  54. 0 episode-206/mailit/public/stylesheets/.gitkeep
  55. +61 −0 episode-206/mailit/public/stylesheets/scaffold.css
  56. +10 −0 episode-206/mailit/script/rails
  57. +9 −0 episode-206/mailit/test/fixtures/users.yml
  58. +8 −0 episode-206/mailit/test/functional/user_mailer_test.rb
  59. +45 −0 episode-206/mailit/test/functional/users_controller_test.rb
  60. +9 −0 episode-206/mailit/test/performance/browsing_test.rb
  61. +13 −0 episode-206/mailit/test/test_helper.rb
  62. +4 −0 episode-206/mailit/test/unit/helpers/users_helper_test.rb
  63. +8 −0 episode-206/mailit/test/unit/user_test.rb
  64. 0 episode-206/mailit/vendor/plugins/.gitkeep
View
@@ -0,0 +1,12 @@
+Railscasts Episode #206: Action Mailer in Rails 3
+
+http://railscasts.com/episodes/206
+
+Commands
+
+ rails mailit
+ cd mailit
+ rails g scaffold user name:string email:string
+ rake db:migrate
+ rails g mailer user_mailer
+ bundle install
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
View
@@ -0,0 +1,26 @@
+# Edit this Gemfile to bundle your application's dependencies.
+source 'http://gemcutter.org'
+
+
+gem "rails", "3.0.0.beta"
+
+## Bundle edge rails:
+# gem "rails", :git => "git://github.com/rails/rails.git"
+
+# ActiveRecord requires a database adapter. By default,
+# Rails has selected sqlite3.
+gem "sqlite3-ruby", :require => "sqlite3"
+
+## Bundle the gems you use:
+# gem "bj"
+# gem "hpricot", "0.6"
+# gem "sqlite3-ruby", :require => "sqlite3"
+# gem "aws-s3", :require => "aws/s3"
+
+## Bundle gems used only in certain environments:
+# gem "rspec", :group => :test
+# group :test do
+# gem "webrat"
+# end
+
+gem "mail", "2.1.3"
@@ -0,0 +1 @@
+Example Railscasts Application
@@ -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,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,85 @@
+class UsersController < ApplicationController
+ # GET /users
+ # GET /users.xml
+ def index
+ @users = User.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @users }
+ end
+ end
+
+ # GET /users/1
+ # GET /users/1.xml
+ def show
+ @user = User.find(params[:id])
+ UserMailer.registration_confirmation(@user).deliver
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @user }
+ end
+ end
+
+ # GET /users/new
+ # GET /users/new.xml
+ def new
+ @user = User.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @user }
+ end
+ end
+
+ # GET /users/1/edit
+ def edit
+ @user = User.find(params[:id])
+ end
+
+ # POST /users
+ # POST /users.xml
+ def create
+ @user = User.new(params[:user])
+
+ respond_to do |format|
+ if @user.save
+ UserMailer.registration_confirmation(@user).deliver
+ format.html { redirect_to(@user, :notice => 'User was successfully created.') }
+ format.xml { render :xml => @user, :status => :created, :location => @user }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /users/1
+ # PUT /users/1.xml
+ def update
+ @user = User.find(params[:id])
+
+ respond_to do |format|
+ if @user.update_attributes(params[:user])
+ format.html { redirect_to(@user, :notice => 'User was successfully updated.') }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /users/1
+ # DELETE /users/1.xml
+ def destroy
+ @user = User.find(params[:id])
+ @user.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(users_url) }
+ format.xml { head :ok }
+ end
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,2 @@
+module UsersHelper
+end
@@ -0,0 +1,9 @@
+class UserMailer < ActionMailer::Base
+ default :from => "ryan@railscasts.com"
+
+ def registration_confirmation(user)
+ @user = user
+ attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
+ mail(:to => "#{user.name} <#{user.email}>", :subject => "Registered")
+ end
+end
@@ -0,0 +1,2 @@
+class User < ActiveRecord::Base
+end
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Users: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+</head>
+<body>
+
+<p class="notice"><%= notice %></p>
+
+<%= yield %>
+
+</body>
+</html>
@@ -0,0 +1,5 @@
+<p><%= @user.name %>,</p>
+
+<p>Thank you for registering!</p>
+
+<p><%= link_to "Edit profile", edit_user_url(@user) %></p>
@@ -0,0 +1,5 @@
+<%= @user.name %>,
+
+Thank you for registering!
+
+Edit profile: <%= edit_user_url(@user) %>
@@ -0,0 +1,15 @@
+<% form_for(@user) do |f| %>
+ <%= f.error_messages %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @user %> |
+<%= link_to 'Back', users_path %>
@@ -0,0 +1,25 @@
+<h1>Listing users</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Email</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%= user.name %></td>
+ <td><%= user.email %></td>
+ <td><%= link_to 'Show', user %></td>
+ <td><%= link_to 'Edit', edit_user_path(user) %></td>
+ <td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New user', new_user_path %>
@@ -0,0 +1,5 @@
+<h1>New user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', users_path %>
@@ -0,0 +1,13 @@
+<p>
+ <b>Name:</b>
+ <%= @user.name %>
+</p>
+
+<p>
+ <b>Email:</b>
+ <%= @user.email %>
+</p>
+
+
+<%= link_to 'Edit', edit_user_path(@user) %> |
+<%= link_to 'Back', users_path %>
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Mailit::Application
@@ -0,0 +1,42 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# Auto-require default libraries and those for the current Rails environment.
+Bundler.require :default, Rails.env
+
+module Mailit
+ 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}')]
+ # 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
+ end
+end
@@ -0,0 +1,17 @@
+# Use Bundler (preferred)
+begin
+ require File.expand_path('../../.bundle/environment', __FILE__)
+rescue LoadError
+ require 'rubygems'
+ require 'bundler'
+ Bundler.setup
+
+ # To use 2.x style vendor/rails and RubyGems
+ #
+ # vendor_rails = File.expand_path('../../vendor/rails', __FILE__)
+ # if File.exist?(vendor_rails)
+ # Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) }
+ # end
+ #
+ # require 'rubygems'
+end
@@ -0,0 +1,22 @@
+# SQLite version 3.x
+# gem install sqlite3-ruby (not necessary on OS X Leopard)
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Mailit::Application.initialize!
@@ -0,0 +1,19 @@
+Mailit::Application.configure do
+ # Settings specified here will take precedence over those in config/environment.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the webserver when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_view.debug_rjs = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+end
Oops, something went wrong.

0 comments on commit 7be4427

Please sign in to comment.