• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Rails 3 Beginner to Builder 2011 Week 6
 

Rails 3 Beginner to Builder 2011 Week 6

on

  • 5,969 views

This is the 6th of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog: ...

This is the 6th of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:


http://schneems.com/tagged/Rails-3-beginner-to-builder-2011

Statistics

Views

Total Views
5,969
Views on SlideShare
1,440
Embed Views
4,529

Actions

Likes
1
Downloads
99
Comments
0

13 Embeds 4,529

http://schneems.com 4109
http://ontwik.com 360
http://teamco-anthill.blogspot.com 25
http://localhost 10
http://www.helpified.com 8
http://teamco-anthill.blogspot.de 4
http://www.hanrss.com 4
https://helpified.com 2
http://www.tumblr.com 2
http://www.schneems.com 2
http://teamco-anthill.blogspot.jp 1
http://teamco-anthill.blogspot.co.uk 1
http://webcache.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Rails 3 Beginner to Builder 2011 Week 6 Rails 3 Beginner to Builder 2011 Week 6 Presentation Transcript

    • Beginner to Builder Week 6June, 2011Wednesday, July 20, 2011
    • Rails - Week 6 • Email in Rails • Background Tasks • modules • Observers & Callbacks • Internationalization & Localization • I18n & L10n@SchneemsWednesday, July 20, 2011
    • Email in Rails • What is Email? • Why Use Email? • How does Rails use email?@SchneemsWednesday, July 20, 2011
    • What is Email • Communications medium defined by RFC standards ✦ RFC = Request for Comments ✦ Comprised of Header & Body ✦ Header (to, from, reply-to, content-type, subject, cc, etc.) ✦ Body (message and attachments)@SchneemsWednesday, July 20, 2011
    • Email- Content Types • Defines How the Mail User Agent (MUA) Interprets Body ✦ Text/HTML ✦ Text/Plain ✦ Multipart/Related (Example: Inline Pictures) ✦ Multipart/Alternative ✦ Send Text/HTML with Text/Plain as backup ✦ Add Attachments@SchneemsWednesday, July 20, 2011
    • Why use Email with Rails? • Status Updates ( Twitter, Facebook, Etc. ) • Direct to Consumer Marketing source • Added functionality (lost passwords, etc.) • Send documents • Everyone has it, and • Everyone can use it@SchneemsWednesday, July 20, 2011
    • How Does RoR Send Email? Mail Server • Low Volume Operating System Your Computer MTA • use Gmail Postfix SMTP • High Volume (Sends d Emails) Their Computer Courier • use a re-mailer IMAP/POP • Build your own@SchneemsWednesday, July 20, 2011
    • How Does RoR Send • ActionMailer • Mail Gem rails generate mailer Notifier /app/mailers/notifier.rb@SchneemsWednesday, July 20, 2011
    • Email With Rails Notifier.signup_notification(“foo@example.com”).deliver@SchneemsWednesday, July 20, 2011
    • Email With Rails • Default Mailer Settings • In-Line Attachments • mail( ) method Notifier.signup_notification(“foo@example.com”).deliver@SchneemsWednesday, July 20, 2011
    • Email With Rails • Default Mailer Settings • In-Line Attachments • mail( ) method Notifier.signup_notification(“foo@example.com”).deliver@SchneemsWednesday, July 20, 2011
    • Email With Rails • Default Mailer Settings • In-Line Attachments • mail( ) method Notifier.signup_notification(“foo@example.com”).deliver@SchneemsWednesday, July 20, 2011
    • Email With Rails ✦ Using Gmail config/environments/development.rb ✦ Use Port 587 ✦ Gmail will throttle large number of email requests ✦ Close to real life conditions ✦ Relatively Easy ✦ Don’t use with automated testing Notifier.signup_notification(“foo@example.com”).deliver@SchneemsWednesday, July 20, 2011
    • Email re-cap ✦ Receiving Email much harder ✦ Also less common ✦ Test your Mailer using an Interceptor ✦ use a re-mailer in production ✦ real life application: http://whyspam.me ✦ No longer running@SchneemsWednesday, July 20, 2011
    • Background Tasks • What is a background task? • Why use one? • Where do i put my task in rails? • How do i keep my task alive?@SchneemsWednesday, July 20, 2011
    • Background Task • What is a background task? • Any server process not initiated by http request • Commonly run for long periods of time • Do not block or stop your application • Clean up server, or application • Generate reports • Much more@SchneemsWednesday, July 20, 2011
    • Background Task • rake tasks • organize code in “lib/tasks” • run with: rake <command> RAILS_ENV=<environment>@SchneemsWednesday, July 20, 2011
    • Background Task • Example • cleanup.rake namespace :cleanup do desc "clean out Tickets over 30 days old" task :old_tickets => :environment do tickets = Ticket.find(:all, :conditions => ["created_at < ?", 30.days.ago ], :limit => 5000) tickets.each do |ticket| ticket.delete end end end rake cleanup:old_tickets@SchneemsWednesday, July 20, 2011
    • Background Task • What if i don’t want to execute from command line? • run task with a automation program • Cron • Monit • God@SchneemsWednesday, July 20, 2011
    • Cron • Very reliable unix time scheduler • Built into the OS • Executes command line calls • Smallest interval is 1 minute • Requires full paths@SchneemsWednesday, July 20, 2011
    • Monit • Not installed on OS by default • Monitors and Executes (cron only executes) • Extra functionality - Sysadmin emails etc...@SchneemsWednesday, July 20, 2011
    • God • Written in ruby • Very configurable • can be memory intensive in some applications sudo gem install god@SchneemsWednesday, July 20, 2011
    • Background • More Options • Workling/Starling • Backgroundrb • ResQue@SchneemsWednesday, July 20, 2011
    • Modules (ruby) • Add “Mixins” to your code • Keep code seperate with different namespaces • put them in your rails project under /lib@SchneemsWednesday, July 20, 2011
    • Modules (ruby) • Example Mixin: • include adds instance methods module AntiCheating class Dog def drug_test include AntiCheating ... end end end puppy = Dog.new puppy.drug_test >> Passed@SchneemsWednesday, July 20, 2011
    • Modules (ruby) • Example Mixin 2: module AntiCheating class Dog def self.cleanup(level) include AntiCheating ... end end end dirtyDog = Dog.new dirtyDog.cleanup >> No Method Error@SchneemsWednesday, July 20, 2011
    • Modules (ruby) • Example Mixin 2: module AntiCheating def self.cleanup(level) ... end end AntiCheating.cleanup >> Very Clean@SchneemsWednesday, July 20, 2011
    • Modules (ruby) • Example Mixin 2: • extend adds all module methods class Dog module AntiCheating extend AntiCheating def self.cleanup(level) end ... end end dirtyDog = Dog.new dirtyDog.cleanup(2) >> “Kinda Clean”@SchneemsWednesday, July 20, 2011
    • Modules (ruby) • Extra Credit: • class << self class Dog class Dog class << self def self.sniff def sniff ... == ... end end end end end@SchneemsWednesday, July 20, 2011
    • Modules (ruby) • Extra Credit: • class << self class Dog module AntiCheating class << self def self.cleanup(level) include AntiCheating ... end end end end dirtyDog = Dog.new dirtyDog.cleanup(10) >> “Really Clean”@SchneemsWednesday, July 20, 2011
    • Modules (ruby) • Example Namespace module FastDogs module SlowDogs class Dog class Dog ... ... end end end end lassie = FastDogs::Dog.new droopy = SlowDogs::Dog.new@SchneemsWednesday, July 20, 2011
    • Callbacks and Observers • Callbacks • Non-polling event based method • hooks into lifecycle of Active Record object • Observers • Implement trigger behavior for class outside of the original class@SchneemsWednesday, July 20, 2011
    • Callbacks • Polling • “Are We there Yet” • Callback • “I’ll tell you when we’re there”@SchneemsWednesday, July 20, 2011
    • Callbacks in Rails save • Lifecycle Hooks => (-) valid (1) before_validation (2) before_validation_on_create (-) validate (-) validate_on_create (3) after_validation (4) after_validation_on_create (5) before_save (6) before_create (-) create (7) after_create (8) after_save@SchneemsWednesday, July 20, 2011
    • Callbacks in Rails • Example • before_destroy class Topic < ActiveRecord::Base before_destroy :delete_parents def delete_parents self.class.delete_all "parent_id = #{id}" end end end@SchneemsWednesday, July 20, 2011
    • Observers • Add callback functionality without polluting the model • Will run after every new user instance is created • Keeps your code clean(er)@SchneemsWednesday, July 20, 2011
    • i18n & L10n Source: @mattt@SchneemsWednesday, July 20, 2011
    • i18n & L10n Source: @mattt@SchneemsWednesday, July 20, 2011
    • language configuration Source: @mattt Source: @mattt@SchneemsWednesday, July 20, 2011
    • Multiple Language Files fr.yml ja.yml Source: @mattt@SchneemsWednesday, July 20, 2011
    • It Worked! Source: @mattt@SchneemsWednesday, July 20, 2011
    • What about L10n@SchneemsWednesday, July 20, 2011
    • Questions? http://guides.rubyonrails.org http://stackoverflow.com http://peepcode.com@SchneemsWednesday, July 20, 2011