Skip to content

Commit

Permalink
automatic import from ryanb/railscasts-episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesbowkett committed Jul 29, 2011
0 parents commit 743dbba
Show file tree
Hide file tree
Showing 64 changed files with 8,335 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README
@@ -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
4 changes: 4 additions & 0 deletions mailit/.gitignore
@@ -0,0 +1,4 @@
.bundle
db/*.sqlite3
log/*.log
tmp/**/*
26 changes: 26 additions & 0 deletions mailit/Gemfile
@@ -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"
1 change: 1 addition & 0 deletions mailit/README
@@ -0,0 +1 @@
Example Railscasts Application
10 changes: 10 additions & 0 deletions mailit/Rakefile
@@ -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
3 changes: 3 additions & 0 deletions mailit/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery
end
84 changes: 84 additions & 0 deletions mailit/app/controllers/users_controller.rb
@@ -0,0 +1,84 @@
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])

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
2 changes: 2 additions & 0 deletions mailit/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
module ApplicationHelper
end
2 changes: 2 additions & 0 deletions mailit/app/helpers/users_helper.rb
@@ -0,0 +1,2 @@
module UsersHelper
end
9 changes: 9 additions & 0 deletions mailit/app/mailers/user_mailer.rb
@@ -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
2 changes: 2 additions & 0 deletions mailit/app/models/user.rb
@@ -0,0 +1,2 @@
class User < ActiveRecord::Base
end
16 changes: 16 additions & 0 deletions mailit/app/views/layouts/users.html.erb
@@ -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) %>
15 changes: 15 additions & 0 deletions mailit/app/views/users/_form.html.erb
@@ -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 %>
6 changes: 6 additions & 0 deletions mailit/app/views/users/edit.html.erb
@@ -0,0 +1,6 @@
<h1>Editing user</h1>

<%= render 'form' %>
<%= link_to 'Show', @user %> |
<%= link_to 'Back', users_path %>
25 changes: 25 additions & 0 deletions mailit/app/views/users/index.html.erb
@@ -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 %>
5 changes: 5 additions & 0 deletions mailit/app/views/users/new.html.erb
@@ -0,0 +1,5 @@
<h1>New user</h1>

<%= render 'form' %>
<%= link_to 'Back', users_path %>
13 changes: 13 additions & 0 deletions mailit/app/views/users/show.html.erb
@@ -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 %>
4 changes: 4 additions & 0 deletions mailit/config.ru
@@ -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
42 changes: 42 additions & 0 deletions mailit/config/application.rb
@@ -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
17 changes: 17 additions & 0 deletions mailit/config/boot.rb
@@ -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
22 changes: 22 additions & 0 deletions mailit/config/database.yml
@@ -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
5 changes: 5 additions & 0 deletions mailit/config/environment.rb
@@ -0,0 +1,5 @@
# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Mailit::Application.initialize!
19 changes: 19 additions & 0 deletions mailit/config/environments/development.rb
@@ -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

0 comments on commit 743dbba

Please sign in to comment.