The Depot Application

The Depot Application

26 Active Resources 23.11 Adding New Templating Systems

25.1 Sending E-mail

ruby -rubygems /home/rubys/git/rails/bin/rails new mailer
      create  
      create  README
      create  Rakefile
      create  config.ru
      create  .gitignore
      create  Gemfile
      create  app
      create  app/helpers/application_helper.rb
      create  app/views/layouts/application.html.erb
      create  app/controllers/application_controller.rb
      create  app/mailers
      create  app/models
      create  config
      create  config/routes.rb
      create  config/application.rb
      create  config/environment.rb
      create  config/environments
      create  config/environments/development.rb
      create  config/environments/test.rb
      create  config/environments/production.rb
      create  config/initializers
      create  config/initializers/mime_types.rb
      create  config/initializers/inflections.rb
      create  config/initializers/session_store.rb
      create  config/initializers/backtrace_silencers.rb
      create  config/initializers/secret_token.rb
      create  config/locales
      create  config/locales/en.yml
      create  config/boot.rb
      create  config/database.yml
      create  db
      create  db/seeds.rb
      create  doc
      create  doc/README_FOR_APP
      create  lib
      create  lib/tasks
      create  lib/tasks/.gitkeep
      create  log
      create  log/server.log
      create  log/production.log
      create  log/development.log
      create  log/test.log
      create  public
      create  public/500.html
      create  public/robots.txt
      create  public/favicon.ico
      create  public/422.html
      create  public/404.html
      create  public/index.html
      create  public/images
      create  public/images/rails.png
      create  public/stylesheets
      create  public/stylesheets/.gitkeep
      create  public/javascripts
      create  public/javascripts/prototype.js
      create  public/javascripts/dragdrop.js
      create  public/javascripts/rails.js
      create  public/javascripts/effects.js
      create  public/javascripts/controls.js
      create  public/javascripts/application.js
      create  script
      create  script/rails
      create  test
      create  test/performance/browsing_test.rb
      create  test/test_helper.rb
      create  test/fixtures
      create  test/unit
      create  test/functional
      create  test/integration
      create  tmp
      create  tmp/sessions
      create  tmp/sockets
      create  tmp/cache
      create  tmp/pids
      create  vendor/plugins
      create  vendor/plugins/.gitkeep
bundle install
Using rake (0.8.7) 
Using abstract (1.0.0) 
Using activesupport (3.0.0.rc) from source at /home/rubys/git/rails 
Using builder (2.1.2) 
Using i18n (0.4.1) 
Using activemodel (3.0.0.rc) from source at /home/rubys/git/rails 
Using erubis (2.6.6) 
Using rack (1.2.1) 
Using rack-mount (0.6.9) 
Using rack-test (0.5.4) 
Using tzinfo (0.3.22) 
Using actionpack (3.0.0.rc) from source at /home/rubys/git/rails 
Using mime-types (1.16) 
Using polyglot (0.3.1) 
Using treetop (1.4.8) 
Using mail (2.2.5) 
Using actionmailer (3.0.0.rc) from source at /home/rubys/git/rails 
Using arel (0.4.0) 
Using activerecord (3.0.0.rc) from source at /home/rubys/git/rails 
Using activeresource (3.0.0.rc) from source at /home/rubys/git/rails 
Using bundler (1.0.0.rc.3) 
Using thor (0.14.0) 
Using railties (3.0.0.rc) from source at /home/rubys/git/rails 
Using rails (3.0.0.rc) from source at /home/rubys/git/rails 
Using sqlite3-ruby (1.3.1) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
*[32m
Your bundle was installed to `/home/rubys/.rvm/gems/ruby-1.8.8-r28862`*[0m
edit config/routes.rb
Mailer::Application.routes.draw do
  # ...
 
  # This is a legacy wild controller route that's not recommended for RESTful applications.
  # Note: This route will make all actions in every controller accessible via GET requests.
   match ':controller(/:action(/:id(.:format)))'
end
rails generate mailer OrderMailer confirm sent
      create  app/mailers/order_mailer.rb
      invoke  erb
      create    app/views/order_mailer
      create    app/views/order_mailer/confirm.text.erb
      create    app/views/order_mailer/sent.text.erb
      invoke  test_unit
      create    test/functional/order_mailer_test.rb
cp -vr /home/rubys/git/awdwr/data/code/e1/mailer/db/migrate db
`/home/rubys/git/awdwr/data/code/e1/mailer/db/migrate' -> `db/migrate'
`/home/rubys/git/awdwr/data/code/e1/mailer/db/migrate/004_populate_data.rb' -> `db/migrate/004_populate_data.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/db/migrate/001_create_products.rb' -> `db/migrate/001_create_products.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/db/migrate/003_create_orders.rb' -> `db/migrate/003_create_orders.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/db/migrate/002_create_line_items.rb' -> `db/migrate/002_create_line_items.rb'
cp -v /home/rubys/git/awdwr/data/code/e1/mailer/app/controllers/* app/controllers
`/home/rubys/git/awdwr/data/code/e1/mailer/app/controllers/application.rb' -> `app/controllers/application.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/controllers/order_controller.rb' -> `app/controllers/order_controller.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/controllers/test_controller.rb' -> `app/controllers/test_controller.rb'
cp -v /home/rubys/git/awdwr/data/code/e1/mailer/app/models/* app/models
`/home/rubys/git/awdwr/data/code/e1/mailer/app/models/incoming_ticket_handler.rb' -> `app/models/incoming_ticket_handler.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/models/line_item.rb' -> `app/models/line_item.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/models/order.rb' -> `app/models/order.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/models/order_mailer.rb' -> `app/models/order_mailer.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/models/product.rb' -> `app/models/product.rb'
cp -vr /home/rubys/git/awdwr/data/code/e1/mailer/test .
`/home/rubys/git/awdwr/data/code/e1/mailer/test/fixtures/orders.yml' -> `./test/fixtures/orders.yml'
`/home/rubys/git/awdwr/data/code/e1/mailer/test/fixtures/order_mailer' -> `./test/fixtures/order_mailer'
`/home/rubys/git/awdwr/data/code/e1/mailer/test/fixtures/order_mailer/confirm' -> `./test/fixtures/order_mailer/confirm'
`/home/rubys/git/awdwr/data/code/e1/mailer/test/fixtures/order_mailer/sent' -> `./test/fixtures/order_mailer/sent'
`/home/rubys/git/awdwr/data/code/e1/mailer/test/fixtures/products.yml' -> `./test/fixtures/products.yml'
`/home/rubys/git/awdwr/data/code/e1/mailer/test/fixtures/line_items.yml' -> `./test/fixtures/line_items.yml'
`/home/rubys/git/awdwr/data/code/e1/mailer/test/functional/order_mailer_test.rb' -> `./test/functional/order_mailer_test.rb'
`/home/rubys/git/awdwr/data/code/e1/mailer/test/functional/order_controller_test.rb' -> `./test/functional/order_controller_test.rb'
cp -vr /home/rubys/git/awdwr/data/code/e1/mailer/app/views/order_mailer app/views
`/home/rubys/git/awdwr/data/code/e1/mailer/app/views/order_mailer/_html_line_item.erb' -> `app/views/order_mailer/_html_line_item.erb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/views/order_mailer/survey.text.plain.erb' -> `app/views/order_mailer/survey.text.plain.erb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/views/order_mailer/survey.text.html.erb' -> `app/views/order_mailer/survey.text.html.erb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/views/order_mailer/confirm.erb' -> `app/views/order_mailer/confirm.erb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/views/order_mailer/sent.erb' -> `app/views/order_mailer/sent.erb'
`/home/rubys/git/awdwr/data/code/e1/mailer/app/views/order_mailer/_line_item.erb' -> `app/views/order_mailer/_line_item.erb'
mv app/models/order_mailer.rb app/mailers/
mv confirm.erb confirm.text.erb
mv _line_item.erb _line_item.text.erb
mv sent.erb sent.html.erb
edit sent.html.erb
<h3>Pragmatic Order Shipped</h3>
<p>
  This is just to let you know that we've shipped your recent order:
</p>
 
<table>
 <tr><th colspan="2">Qty</th><th>Description</th></tr>
 <%= render(:partial => "line_item", :collection => @order.line_items) %>
</table>
mv _html_line_item.erb _line_item.html.erb
edit _line_item.html.erb
<tr>
 <td><%= line_item.quantity %></td>
 <td>&times;</td>
 <td><%= line_item.product.title %></td>
</tr>
rm sent.text.erb

Restart the server.

rake db:migrate
mv 001_create_products.rb 20100301000001_create_products.rb
mv 002_create_line_items.rb 20100301000002_create_line_items.rb
mv 003_create_orders.rb 20100301000003_create_orders.rb
mv 004_populate_data.rb 20100301000004_populate_data.rb
(in /home/rubys/git/awdwr/work-188/mailer)
==  CreateProducts: migrating =================================================
-- create_table(:products)
   -> 0.0019s
==  CreateProducts: migrated (0.0020s) ========================================
 
==  CreateLineItems: migrating ================================================
-- create_table(:line_items)
   -> 0.0016s
==  CreateLineItems: migrated (0.0017s) =======================================
 
==  CreateOrders: migrating ===================================================
-- create_table(:orders)
   -> 0.0017s
==  CreateOrders: migrated (0.0018s) ==========================================
 
==  PopulateData: migrating ===================================================
==  PopulateData: migrated (0.0824s) ==========================================
 
get /test/create_order
Date: Sat, 07 Aug 2010 09:23:33 -0400
From: orders@example.com
To: dave@example.com
Message-ID: <4c5d5e56247d3_1e5b2495c66e127e4@rubix.mail>
Subject: Pragmatic Store Order Confirmation
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

Dear Dave Thomas

Thank you for your recent order from The Pragmatic Store.

You ordered the following items:

 1 x Programming Ruby, 2nd Edition
 1 x Pragmatic Project Automation


We'll send you a separate e-mail when your order ships.


get /test/ship_order
Thank you...
rake test
(in /home/rubys/git/awdwr/work-188/mailer)
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.8-r28862/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
DEPRECATION WARNING: OrderMailer.deliver_confirm is deprecated, use OrderMailer.confirm.deliver instead. (called from method_missing at /home/rubys/git/rails/actionmailer/lib/action_mailer/base.rb:427)
DEPRECATION WARNING: Giving a hash to body is deprecated, please use instance variables instead. (called from process at /home/rubys/git/rails/actionmailer/lib/action_mailer/old_api.rb:77)
DEPRECATION WARNING: OrderMailer.create_confirm is deprecated, use OrderMailer.confirm instead. (called from method_missing at /home/rubys/git/rails/actionmailer/lib/action_mailer/base.rb:427)
DEPRECATION WARNING: Giving a hash to body is deprecated, please use instance variables instead. (called from process at /home/rubys/git/rails/actionmailer/lib/action_mailer/old_api.rb:77)
DEPRECATION WARNING: OrderMailer.create_sent is deprecated, use OrderMailer.sent instead. (called from method_missing at /home/rubys/git/rails/actionmailer/lib/action_mailer/base.rb:427)
DEPRECATION WARNING: Giving a hash to body is deprecated, please use instance variables instead. (called from process at /home/rubys/git/rails/actionmailer/lib/action_mailer/old_api.rb:77)
...
Finished in 0.182148 seconds.
 
3 tests, 9 assertions, 0 failures, 0 errors

26 Active Resources 23.11 Adding New Templating Systems