This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
8,336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
.bundle | |||
db/*.sqlite3 | |||
log/*.log | |||
tmp/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
Example Railscasts Application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
class ApplicationController < ActionController::Base | |||
protect_from_forgery | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
module ApplicationHelper | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
module UsersHelper | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
class User < ActiveRecord::Base | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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> |
5 changes: 5 additions & 0 deletions
5
episode-206/mailit/app/views/user_mailer/registration_confirmation.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
<p><%= @user.name %>,</p> | |||
|
|||
<p>Thank you for registering!</p> | |||
|
|||
<p><%= link_to "Edit profile", edit_user_url(@user) %></p> |
5 changes: 5 additions & 0 deletions
5
episode-206/mailit/app/views/user_mailer/registration_confirmation.text.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
<%= @user.name %>, | |||
|
|||
Thank you for registering! | |||
|
|||
Edit profile: <%= edit_user_url(@user) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
<h1>Editing user</h1> | |||
|
|||
<%= render 'form' %> | |||
<%= link_to 'Show', @user %> | | |||
<%= link_to 'Back', users_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
<h1>New user</h1> | |||
|
|||
<%= render 'form' %> | |||
<%= link_to 'Back', users_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
# Load the rails application | |||
require File.expand_path('../application', __FILE__) | |||
|
|||
# Initialize the rails application | |||
Mailit::Application.initialize! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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.