SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
Beginner to Builder
                           Week 6




June, 2011
Wednesday, July 20, 2011
Rails - Week 6
                    • Email in Rails
                    • Background Tasks
                    • modules
                    • Observers & Callbacks
                    • Internationalization & Localization
                      • I18n & L10n

@Schneems
Wednesday, July 20, 2011
Email in Rails
        • What is Email?
        • Why Use Email?
        • How does Rails use email?




@Schneems
Wednesday, 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)




@Schneems
Wednesday, 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


@Schneems
Wednesday, 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



@Schneems
Wednesday, 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


@Schneems
Wednesday, July 20, 2011
How Does RoR Send
      •      ActionMailer

           •       Mail Gem


                           rails generate mailer Notifier




                                     /app/mailers/notifier.rb



@Schneems
Wednesday, July 20, 2011
Email With Rails




        Notifier.signup_notification(“foo@example.com”).deliver
@Schneems
Wednesday, July 20, 2011
Email With Rails
                                         • Default Mailer
                                         Settings


                                         • In-Line Attachments

                                         • mail( ) method

        Notifier.signup_notification(“foo@example.com”).deliver
@Schneems
Wednesday, July 20, 2011
Email With Rails
                                         • Default Mailer
                                         Settings


                                         • In-Line Attachments

                                         • mail( ) method

        Notifier.signup_notification(“foo@example.com”).deliver
@Schneems
Wednesday, July 20, 2011
Email With Rails
                                         • Default Mailer
                                         Settings


                                         • In-Line Attachments

                                         • mail( ) method

        Notifier.signup_notification(“foo@example.com”).deliver
@Schneems
Wednesday, 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
@Schneems
Wednesday, 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




@Schneems
Wednesday, 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?



@Schneems
Wednesday, 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
@Schneems
Wednesday, July 20, 2011
Background Task
    • rake tasks
     • organize code in “lib/tasks”
       • run with:

                           rake <command> RAILS_ENV=<environment>




@Schneems
Wednesday, 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

@Schneems
Wednesday, 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


@Schneems
Wednesday, 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


@Schneems
Wednesday, July 20, 2011
Monit
        • Not installed on OS by default
          • Monitors and Executes (cron only executes)
        • Extra functionality - Sysadmin emails etc...




@Schneems
Wednesday, July 20, 2011
God	
        • Written in ruby
        • Very configurable
        • can be memory
          intensive in some
                applications




                           sudo gem install god


@Schneems
Wednesday, July 20, 2011
Background
        • More Options
          • Workling/Starling
          • Backgroundrb
          • ResQue



@Schneems
Wednesday, July 20, 2011
Modules (ruby)
    • Add “Mixins” to your code
    • Keep code seperate with different namespaces
    • put them in your rails project under /lib




@Schneems
Wednesday, 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
@Schneems
Wednesday, 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

@Schneems
Wednesday, July 20, 2011
Modules (ruby)
   • Example Mixin 2:
                           module AntiCheating
                             def self.cleanup(level)
                               ...
                             end
                           end


                              AntiCheating.cleanup
                              >> Very Clean



@Schneems
Wednesday, 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”

@Schneems
Wednesday, 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



@Schneems
Wednesday, 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”
@Schneems
Wednesday, 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




@Schneems
Wednesday, 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




@Schneems
Wednesday, July 20, 2011
Callbacks
    • Polling
     • “Are We there Yet”
    • Callback
     • “I’ll tell you when we’re there”



@Schneems
Wednesday, 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

@Schneems
Wednesday, 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



@Schneems
Wednesday, 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)
@Schneems
Wednesday, July 20, 2011
i18n & L10n




                            Source: @mattt
@Schneems
Wednesday, July 20, 2011
i18n & L10n




                           Source: @mattt

@Schneems
Wednesday, July 20, 2011
language configuration
                                            Source: @mattt




                           Source: @mattt

@Schneems
Wednesday, July 20, 2011
Multiple Language Files
                           fr.yml




                                    ja.yml




                                       Source: @mattt
@Schneems
Wednesday, July 20, 2011
It Worked!




                                  Source: @mattt
@Schneems
Wednesday, July 20, 2011
What about L10n




@Schneems
Wednesday, July 20, 2011
Questions?
                           http://guides.rubyonrails.org
                            http://stackoverflow.com
                               http://peepcode.com


@Schneems
Wednesday, July 20, 2011

Mais conteúdo relacionado

Destaque

AJAX?? Não!! Asynchronous Javascript and... JSON!!
AJAX?? Não!! Asynchronous Javascript and... JSON!!AJAX?? Não!! Asynchronous Javascript and... JSON!!
AJAX?? Não!! Asynchronous Javascript and... JSON!!Lucas Brasilino
 
Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3Richard Schneeman
 
Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2Richard Schneeman
 
Minicurso JSON & Ajax
Minicurso JSON & AjaxMinicurso JSON & Ajax
Minicurso JSON & AjaxWilker Iceri
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentationadamcookeuk
 

Destaque (6)

AJAX?? Não!! Asynchronous Javascript and... JSON!!
AJAX?? Não!! Asynchronous Javascript and... JSON!!AJAX?? Não!! Asynchronous Javascript and... JSON!!
AJAX?? Não!! Asynchronous Javascript and... JSON!!
 
Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3Rails 3 Beginner to Builder 2011 Week 3
Rails 3 Beginner to Builder 2011 Week 3
 
Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2Rails 3 Beginner to Builder 2011 Week 2
Rails 3 Beginner to Builder 2011 Week 2
 
Minicurso JSON & Ajax
Minicurso JSON & AjaxMinicurso JSON & Ajax
Minicurso JSON & Ajax
 
Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 

Semelhante a Rails 3 Beginner to Builder 2011 Week 6

Modern Web Technologies — Jerusalem Web Professionals, January 2011
Modern Web Technologies — Jerusalem Web Professionals, January 2011Modern Web Technologies — Jerusalem Web Professionals, January 2011
Modern Web Technologies — Jerusalem Web Professionals, January 2011Reuven Lerner
 
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...Reuven Lerner
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGuillaume Laforge
 
Winning the Big Data SPAM Challenge__HadoopSummit2010
Winning the Big Data SPAM Challenge__HadoopSummit2010Winning the Big Data SPAM Challenge__HadoopSummit2010
Winning the Big Data SPAM Challenge__HadoopSummit2010Yahoo Developer Network
 
Javascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSJavascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSSylvain Zimmer
 
Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011Bachkoutou Toutou
 
AppScale Talk at SBonRails
AppScale Talk at SBonRailsAppScale Talk at SBonRails
AppScale Talk at SBonRailsChris Bunch
 
Chirp 2010: Scaling Twitter
Chirp 2010: Scaling TwitterChirp 2010: Scaling Twitter
Chirp 2010: Scaling TwitterJohn Adams
 
Scoping call presentation_rev_4_mary
Scoping call presentation_rev_4_maryScoping call presentation_rev_4_mary
Scoping call presentation_rev_4_maryrhochambeau32
 
Inside Wordnik's Architecture
Inside Wordnik's ArchitectureInside Wordnik's Architecture
Inside Wordnik's ArchitectureTony Tam
 
SharePoint SpeedMetal Admin 101 - SPSDEN
SharePoint SpeedMetal Admin 101 - SPSDENSharePoint SpeedMetal Admin 101 - SPSDEN
SharePoint SpeedMetal Admin 101 - SPSDENChris McNulty
 
"How Mozilla Uses Selenium"
"How Mozilla Uses Selenium""How Mozilla Uses Selenium"
"How Mozilla Uses Selenium"Stephen Donner
 
Rails3 Summer of Code 2010 - Week 6
Rails3 Summer of Code 2010 - Week 6Rails3 Summer of Code 2010 - Week 6
Rails3 Summer of Code 2010 - Week 6Richard Schneeman
 
Class 1 - World Wide Web Introduction
Class 1 - World Wide Web IntroductionClass 1 - World Wide Web Introduction
Class 1 - World Wide Web IntroductionAhmed Swilam
 
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)Ingo Renner
 
Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1Tuenti
 
How I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTreeHow I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTreeHajime Morrita
 
Voight-Kampff for Email Addresses: Quantifying Email Address Reputation to Id...
Voight-Kampff for Email Addresses: Quantifying Email Address Reputation to Id...Voight-Kampff for Email Addresses: Quantifying Email Address Reputation to Id...
Voight-Kampff for Email Addresses: Quantifying Email Address Reputation to Id...Joshua Kamdjou
 

Semelhante a Rails 3 Beginner to Builder 2011 Week 6 (20)

Modern Web Technologies — Jerusalem Web Professionals, January 2011
Modern Web Technologies — Jerusalem Web Professionals, January 2011Modern Web Technologies — Jerusalem Web Professionals, January 2011
Modern Web Technologies — Jerusalem Web Professionals, January 2011
 
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...
Modern Web technologies (and why you should care): Megacomm, Jerusalem, Febru...
 
library h3lp
library h3lplibrary h3lp
library h3lp
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
 
Winning the Big Data SPAM Challenge__HadoopSummit2010
Winning the Big Data SPAM Challenge__HadoopSummit2010Winning the Big Data SPAM Challenge__HadoopSummit2010
Winning the Big Data SPAM Challenge__HadoopSummit2010
 
Javascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSJavascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJS
 
Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011Sean coates fifty things and tricks, confoo 2011
Sean coates fifty things and tricks, confoo 2011
 
AppScale Talk at SBonRails
AppScale Talk at SBonRailsAppScale Talk at SBonRails
AppScale Talk at SBonRails
 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
 
Chirp 2010: Scaling Twitter
Chirp 2010: Scaling TwitterChirp 2010: Scaling Twitter
Chirp 2010: Scaling Twitter
 
Scoping call presentation_rev_4_mary
Scoping call presentation_rev_4_maryScoping call presentation_rev_4_mary
Scoping call presentation_rev_4_mary
 
Inside Wordnik's Architecture
Inside Wordnik's ArchitectureInside Wordnik's Architecture
Inside Wordnik's Architecture
 
SharePoint SpeedMetal Admin 101 - SPSDEN
SharePoint SpeedMetal Admin 101 - SPSDENSharePoint SpeedMetal Admin 101 - SPSDEN
SharePoint SpeedMetal Admin 101 - SPSDEN
 
"How Mozilla Uses Selenium"
"How Mozilla Uses Selenium""How Mozilla Uses Selenium"
"How Mozilla Uses Selenium"
 
Rails3 Summer of Code 2010 - Week 6
Rails3 Summer of Code 2010 - Week 6Rails3 Summer of Code 2010 - Week 6
Rails3 Summer of Code 2010 - Week 6
 
Class 1 - World Wide Web Introduction
Class 1 - World Wide Web IntroductionClass 1 - World Wide Web Introduction
Class 1 - World Wide Web Introduction
 
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
Apache Solr for TYPO3 (@ T3CON10 Dallas, TX)
 
Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1Tuenti Release Workflow v1.1
Tuenti Release Workflow v1.1
 
How I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTreeHow I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTree
 
Voight-Kampff for Email Addresses: Quantifying Email Address Reputation to Id...
Voight-Kampff for Email Addresses: Quantifying Email Address Reputation to Id...Voight-Kampff for Email Addresses: Quantifying Email Address Reputation to Id...
Voight-Kampff for Email Addresses: Quantifying Email Address Reputation to Id...
 

Mais de Richard Schneeman

Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLRichard Schneeman
 
Rails 3 Beginner to Builder 2011 Week 8
Rails 3 Beginner to Builder 2011 Week 8Rails 3 Beginner to Builder 2011 Week 8
Rails 3 Beginner to Builder 2011 Week 8Richard Schneeman
 
Rails 3 Beginner to Builder 2011 Week 4
Rails 3 Beginner to Builder 2011 Week 4Rails 3 Beginner to Builder 2011 Week 4
Rails 3 Beginner to Builder 2011 Week 4Richard Schneeman
 
Rails3 Summer of Code 2010- Week 5
Rails3 Summer of Code 2010- Week 5Rails3 Summer of Code 2010- Week 5
Rails3 Summer of Code 2010- Week 5Richard Schneeman
 

Mais de Richard Schneeman (8)

Scaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQLScaling the Web: Databases & NoSQL
Scaling the Web: Databases & NoSQL
 
Rails 3 Beginner to Builder 2011 Week 8
Rails 3 Beginner to Builder 2011 Week 8Rails 3 Beginner to Builder 2011 Week 8
Rails 3 Beginner to Builder 2011 Week 8
 
Rails 3 Beginner to Builder 2011 Week 4
Rails 3 Beginner to Builder 2011 Week 4Rails 3 Beginner to Builder 2011 Week 4
Rails 3 Beginner to Builder 2011 Week 4
 
Potential Friend Finder
Potential Friend FinderPotential Friend Finder
Potential Friend Finder
 
Rails3 Summer of Code 2010- Week 5
Rails3 Summer of Code 2010- Week 5Rails3 Summer of Code 2010- Week 5
Rails3 Summer of Code 2010- Week 5
 
UT on Rails3 2010- Week 4
UT on Rails3 2010- Week 4 UT on Rails3 2010- Week 4
UT on Rails3 2010- Week 4
 
UT on Rails3 2010- Week 2
UT on Rails3 2010- Week 2UT on Rails3 2010- Week 2
UT on Rails3 2010- Week 2
 
UT on Rails3 2010- Week 1
UT on Rails3 2010- Week 1UT on Rails3 2010- Week 1
UT on Rails3 2010- Week 1
 

Último

Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 

Último (20)

Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 

Rails 3 Beginner to Builder 2011 Week 6

  • 1. Beginner to Builder Week 6 June, 2011 Wednesday, July 20, 2011
  • 2. Rails - Week 6 • Email in Rails • Background Tasks • modules • Observers & Callbacks • Internationalization & Localization • I18n & L10n @Schneems Wednesday, July 20, 2011
  • 3. Email in Rails • What is Email? • Why Use Email? • How does Rails use email? @Schneems Wednesday, July 20, 2011
  • 4. 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) @Schneems Wednesday, July 20, 2011
  • 5. 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 @Schneems Wednesday, July 20, 2011
  • 6. 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 @Schneems Wednesday, July 20, 2011
  • 7. 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 @Schneems Wednesday, July 20, 2011
  • 8. How Does RoR Send • ActionMailer • Mail Gem rails generate mailer Notifier /app/mailers/notifier.rb @Schneems Wednesday, July 20, 2011
  • 9. Email With Rails Notifier.signup_notification(“foo@example.com”).deliver @Schneems Wednesday, July 20, 2011
  • 10. Email With Rails • Default Mailer Settings • In-Line Attachments • mail( ) method Notifier.signup_notification(“foo@example.com”).deliver @Schneems Wednesday, July 20, 2011
  • 11. Email With Rails • Default Mailer Settings • In-Line Attachments • mail( ) method Notifier.signup_notification(“foo@example.com”).deliver @Schneems Wednesday, July 20, 2011
  • 12. Email With Rails • Default Mailer Settings • In-Line Attachments • mail( ) method Notifier.signup_notification(“foo@example.com”).deliver @Schneems Wednesday, July 20, 2011
  • 13. 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 @Schneems Wednesday, July 20, 2011
  • 14. 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 @Schneems Wednesday, July 20, 2011
  • 15. 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? @Schneems Wednesday, July 20, 2011
  • 16. 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 @Schneems Wednesday, July 20, 2011
  • 17. Background Task • rake tasks • organize code in “lib/tasks” • run with: rake <command> RAILS_ENV=<environment> @Schneems Wednesday, July 20, 2011
  • 18. 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 @Schneems Wednesday, July 20, 2011
  • 19. Background Task • What if i don’t want to execute from command line? • run task with a automation program • Cron • Monit • God @Schneems Wednesday, July 20, 2011
  • 20. Cron • Very reliable unix time scheduler • Built into the OS • Executes command line calls • Smallest interval is 1 minute • Requires full paths @Schneems Wednesday, July 20, 2011
  • 21. Monit • Not installed on OS by default • Monitors and Executes (cron only executes) • Extra functionality - Sysadmin emails etc... @Schneems Wednesday, July 20, 2011
  • 22. God • Written in ruby • Very configurable • can be memory intensive in some applications sudo gem install god @Schneems Wednesday, July 20, 2011
  • 23. Background • More Options • Workling/Starling • Backgroundrb • ResQue @Schneems Wednesday, July 20, 2011
  • 24. Modules (ruby) • Add “Mixins” to your code • Keep code seperate with different namespaces • put them in your rails project under /lib @Schneems Wednesday, July 20, 2011
  • 25. 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 @Schneems Wednesday, July 20, 2011
  • 26. 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 @Schneems Wednesday, July 20, 2011
  • 27. Modules (ruby) • Example Mixin 2: module AntiCheating def self.cleanup(level) ... end end AntiCheating.cleanup >> Very Clean @Schneems Wednesday, July 20, 2011
  • 28. 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” @Schneems Wednesday, July 20, 2011
  • 29. Modules (ruby) • Extra Credit: • class << self class Dog class Dog class << self def self.sniff def sniff ... == ... end end end end end @Schneems Wednesday, July 20, 2011
  • 30. 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” @Schneems Wednesday, July 20, 2011
  • 31. Modules (ruby) • Example Namespace module FastDogs module SlowDogs class Dog class Dog ... ... end end end end lassie = FastDogs::Dog.new droopy = SlowDogs::Dog.new @Schneems Wednesday, July 20, 2011
  • 32. 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 @Schneems Wednesday, July 20, 2011
  • 33. Callbacks • Polling • “Are We there Yet” • Callback • “I’ll tell you when we’re there” @Schneems Wednesday, July 20, 2011
  • 34. 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 @Schneems Wednesday, July 20, 2011
  • 35. 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 @Schneems Wednesday, July 20, 2011
  • 36. Observers • Add callback functionality without polluting the model • Will run after every new user instance is created • Keeps your code clean(er) @Schneems Wednesday, July 20, 2011
  • 37. i18n & L10n Source: @mattt @Schneems Wednesday, July 20, 2011
  • 38. i18n & L10n Source: @mattt @Schneems Wednesday, July 20, 2011
  • 39. language configuration Source: @mattt Source: @mattt @Schneems Wednesday, July 20, 2011
  • 40. Multiple Language Files fr.yml ja.yml Source: @mattt @Schneems Wednesday, July 20, 2011
  • 41. It Worked! Source: @mattt @Schneems Wednesday, July 20, 2011
  • 43. Questions? http://guides.rubyonrails.org http://stackoverflow.com http://peepcode.com @Schneems Wednesday, July 20, 2011