SlideShare una empresa de Scribd logo
1 de 447
This content is available free on   created by
http://RailsForZombies.org
Feel free to delete this slide




 This means you can use the If you need to charge some
 content:                    money
 * You can modify / remix it to run an event which uses this
                             content
                                   it can not be profitable. i.e. You
                                   should only be charging enough
 However:                          to cover costs.
 * You can’t charge money for it
                            If profit is involved, Envy Labs
 * You must keep the attribution deserves a small cut,
                            probably
                                   don’t you think? Maybe even
                                   consider having Envy Labs teach
                                   it in person perhaps?
                                   Email => Gregg@EnvyLabs.com
          This content is available free on      created by
          http://RailsForZombies.org
Recommendations for running
•You’ll need 3-4 for Zombies through the
      a Live Rails hours to get
  tutorial, with enough time for labs
               Tutorial
•Present these slides, then give students
20-30
  minutes do do the exercises on
RailsForZombies.org
•Have students go through TryRuby.org
ahead of time,
  if they’re not familiar with Ruby
•If you’re not comfortable with presenting
this material
  feel free to just play the videos on the
website and                 Feel free to delete this slid
  not use these slides available free on created by
          This content is
         http://RailsForZombies.org
Recommendations for creating
  •Make each episode a separate video, not one long
  one.            a
  •If possible, don’t use slides
    video with these your laptop microphone, use
  a
    USB Microphone like: http://amzn.to/eHTMSJ
  •Seeing your face is more entertaining then just
   watching code. Please insert yourself into the
  content.
  •Keynote allows you to “Record Slideshow”, which is
  good for
   pacing the timing of the slides (not audio though).
  You can
   then export video with that timing. You’d then
  take this into
   another video editor. (this is how you to delete this slid
                                Feel free export with
  animations) content is available free on
             This                              created by
   If you need an editor suggestion: Screenflow
             http://RailsForZombies.org
An Introduction to
                    Rails
                     Episode #1




This content is available free on   created by
http://RailsForZombies.org
Prerequisites:
TryRuby.org
Episode #1
             Deep in the
FOR ZO
F     MB IES!!
             !
CRU
 D
CRU
          D

tweets
CRU
                        D

              tweets

Rows      {
(we have 4)
CRU
                       Columns         D


Rows      {
(we have 4)
              {
              tweets
                        (we have 3)
CRU
 D
CRU
      D
id
CRU
               D
id   status
CRU
                        D
id   status   zombie
CRU
                                        D
   id     status     zombie




Zombie Challenge #1
    Retrieve a hash of the tweet with id =
                      3
CRU
                                                         D
    id      status          zombie




Zombie Challenge #1
    Retrieve a hash of the tweet with id =
                      3
  Result
     b = { :status => "I just ate some delicious brains",
           :zombie => "Jim" }
CRU
Hash                                                    D
    Series of key value pairs
b = { :status => "I just ate some delicious brains",
      :zombie => "Jim" }
CRU
Hash                                                    D
    Series of key value pairs
b = { :status => "I just ate some delicious brains",
      :zombie => "Jim" }


puts b[:status]
CRU
Hash                                                    D
    Series of key value pairs
b = { :status => "I just ate some delicious brains",
      :zombie => "Jim" }


puts b[:status]

     "I just ate some delicious brains"
CRU
Hash                                                    D
    Series of key value pairs
b = { :status => "I just ate some delicious brains",
      :zombie => "Jim" }


puts b[:status]

     "I just ate some delicious brains"


puts b[:zombie]
CRU
Hash                                                    D
    Series of key value pairs
b = { :status => "I just ate some delicious brains",
      :zombie => "Jim" }


puts b[:status]

     "I just ate some delicious brains"


puts b[:zombie]

                                 "Jim"
CRU
Hash                                                    D
    Series of key value pairs
b = { :status => "I just ate some delicious brains",
      :zombie => "Jim" }


puts b[:status]

     "I just ate some delicious brains"


puts b[:zombie]

                                  "Jim"


puts b[:zombie] + " said " + b[:status]
CRU
Hash                                                      D
      Series of key value pairs
  b = { :status => "I just ate some delicious brains",
        :zombie => "Jim" }


  puts b[:status]

       "I just ate some delicious brains"


  puts b[:zombie]

                                    "Jim"


 puts b[:zombie] + " said " + b[:status]

"Jim said I just ate some delicious brains"
CRU
Hash                                                      D
      Series of key value pairs
  b = { :status => "I just ate some delicious brains",
        :zombie => "Jim" }


  puts b[:status]

       "I just ate some delicious brains"


  puts b[:zombie]

                                    "Jim"


 puts b[:zombie] + " said " + b[:status]

"Jim said I just ate some delicious brains"
CRU
 D
CRU
tweets                                                       D
id                     status                      zombie
 1   Where can I get a good bite to eat?         Ash
 2   My left arm is missing, but I don't care.   Bob
 3   I just ate some delicious brains.           Jim
 4   OMG, my fingers turned green. #FML           Ash
CRU
  tweets                                                        D
  id                      status                      zombie
   1    Where can I get a good bite to eat?         Ash
   2    My left arm is missing, but I don't care.   Bob
   3    I just ate some delicious brains.           Jim
   4    OMG, my fingers turned green. #FML           Ash


ombie Challenge #1
       Retrieve a hash of the tweet with id = 3
CRU
  tweets                                                        D
  id                      status                      zombie
   1    Where can I get a good bite to eat?         Ash
   2    My left arm is missing, but I don't care.   Bob
   3    I just ate some delicious brains.           Jim
   4    OMG, my fingers turned green. #FML           Ash


ombie Challenge #1
       Retrieve a hash of the tweet with id = 3

Answer t          = Tweet.find(3)
CRU
  tweets                                                        D
  id                      status                      zombie
   1    Where can I get a good bite to eat?         Ash
   2    My left arm is missing, but I don't care.   Bob
   3    I just ate some delicious brains.           Jim
   4    OMG, my fingers turned green. #FML           Ash


ombie Challenge #1
       Retrieve a hash of the tweet with id = 3

Answer t          = Tweet.find(3)

               puts t[:id]
CRU
  tweets                                                        D
  id                      status                      zombie
   1    Where can I get a good bite to eat?         Ash
   2    My left arm is missing, but I don't care.   Bob
   3    I just ate some delicious brains.           Jim
   4    OMG, my fingers turned green. #FML           Ash


ombie Challenge #1
       Retrieve a hash of the tweet with id = 3

Answer t          = Tweet.find(3)

               puts t[:id]                  3
CRU
  tweets                                                        D
  id                      status                      zombie
   1    Where can I get a good bite to eat?         Ash
   2    My left arm is missing, but I don't care.   Bob
   3    I just ate some delicious brains.           Jim
   4    OMG, my fingers turned green. #FML           Ash


ombie Challenge #1
       Retrieve a hash of the tweet with id = 3

Answer t          = Tweet.find(3)

               puts t[:id]                  3

               puts t[:status]
CRU
  tweets                                                                 D
  id                      status                      zombie
   1    Where can I get a good bite to eat?         Ash
   2    My left arm is missing, but I don't care.   Bob
   3    I just ate some delicious brains.           Jim
   4    OMG, my fingers turned green. #FML           Ash


ombie Challenge #1
       Retrieve a hash of the tweet with id = 3

Answer t          = Tweet.find(3)

               puts t[:id]                  3

               puts t[:status]              "I just ate some delicious brains."
CRU
  tweets                                                                 D
  id                      status                      zombie
   1    Where can I get a good bite to eat?         Ash
   2    My left arm is missing, but I don't care.   Bob
   3    I just ate some delicious brains.           Jim
   4    OMG, my fingers turned green. #FML           Ash


ombie Challenge #1
       Retrieve a hash of the tweet with id = 3

Answer t          = Tweet.find(3)

               puts t[:id]                  3

               puts t[:status]              "I just ate some delicious brains."


               puts t[:zombie]
CRU
  tweets                                                                 D
  id                      status                      zombie
   1    Where can I get a good bite to eat?         Ash
   2    My left arm is missing, but I don't care.   Bob
   3    I just ate some delicious brains.           Jim
   4    OMG, my fingers turned green. #FML           Ash


ombie Challenge #1
       Retrieve a hash of the tweet with id = 3

Answer t          = Tweet.find(3)

               puts t[:id]                  3

               puts t[:status]              "I just ate some delicious brains."


               puts t[:zombie]              "Jim"
CRU
              t = Tweet.find(3)
                                   D
puts t[:id]


puts t[:status]


puts t[:zombie]
CRU
              t = Tweet.find(3)
                                               D
puts t[:id]                       puts t.id




                  Sam
puts t[:status]




                     eA
puts t[:zombie]




                       s
CRU
              t = Tweet.find(3)
                                               D
puts t[:id]                       puts t.id




                  Sam
puts t[:status]                   puts t.status




                     eA
puts t[:zombie]




                       s
CRU
              t = Tweet.find(3)
                                               D
puts t[:id]                       puts t.id




                  Sam
puts t[:status]                   puts t.status




                     eA
puts t[:zombie]                   puts t.zombie



                       s
CRU
                     t = Tweet.find(3)
                                                        D
    puts t[:id]                          puts t.id




                         Sam
     puts t[:status]                     puts t.status




                            eA
     puts t[:zombie]                     puts t.zombie



                              s
Answer puts   t.id          3

        puts t.status       "I just ate some delicious brains."


        puts t.zombie       "Jim"
CRU
t = Tweet.find(3)
                     D
CRU
                     t = Tweet.find(3)
                                                             D




tweets
id                     status                      zombie
 1   Where can I get a good bite to eat?         Ash
 2   My left arm is missing, but I don't care.   Bob
 3   I just ate some delicious brains.           Jim
 4   OMG, my fingers turned green. #FML           Ash
CRU
                     t = Tweet.find(3)
                                                             D

              Pluralize

tweets
id                     status                      zombie
 1   Where can I get a good bite to eat?         Ash
 2   My left arm is missing, but I don't care.   Bob
 3   I just ate some delicious brains.           Jim
 4   OMG, my fingers turned green. #FML           Ash
C


R



U


D
Create


Read



Update


Delete
Create


Read



Update


Delete
t = Tweet.new
Create   t.status = "I <3 brains."
         t.save




Read



Update


Delete
t = Tweet.new
Create   t.status = "I <3 brains."
         t.save




Read     Tweet.find(3)




Update


Delete
t = Tweet.new
Create   t.status = "I <3 brains."
         t.save




Read     Tweet.find(3)




         t = Tweet.find(3)
Update   t.zombie = "EyeballChomper"
         t.save




Delete
t = Tweet.new
Create   t.status = "I <3 brains."
         t.save




Read     Tweet.find(3)




         t = Tweet.find(3)
Update   t.zombie = "EyeballChomper"
         t.save




         t = Tweet.find(3)
Delete   t.destroy
Create                      Syntax

t = Tweet.new
t.status = "I <3 brains."
t.zombie = "Jim"
t.save
Create                                          Syntax

                                                  the  id .
t = Tweet.new
                                          n’t set    a lly
                                    e  do        anu
t.status = "I <3   brains."
                            tic e w s set m
t.zombie = "Jim"         No           et
t.save                       he  id g or us.
                           T            f
Create                                          Syntax

                                                  the  id .
t = Tweet.new
                                          n’t set    a lly
                                    e  do        anu
t.status = "I <3   brains."
                            tic e w s set m
t.zombie = "Jim"         No           et
t.save                       he  id g or us.
                           T            f
Alternate Syntax
Create                                          Syntax

                                                  the  id .
t = Tweet.new
                                          n’t set    a lly
                                    e  do        anu
t.status = "I <3   brains."
                            tic e w s set m
t.zombie = "Jim"         No           et
t.save                       he  id g or us.
                           T            f
Alternate Syntax
t = Tweet.new(:status => "I <3 brains", :zombie => "Jim")
t.save
Create                                           Syntax

                                                  the  id .
t = Tweet.new
                                          n’t set    a lly
                                    e  do        anu
t.status = "I <3   brains."
                            tic e w s set m
t.zombie = "Jim"         No           et
t.save                       he  id g or us.
                           T            f
Alternate Syntax
t = Tweet.new(:status => "I <3 brains", :zombie => "Jim")
t.save



 Tweet.create(:status => "I <3 brains", :zombie => "Jim")
Read   Syntax
Read                                Syntax

Tweet.find(2)   # Returns a single item
Read                                       Syntax

Tweet.find(2)         # Returns a single item

Tweet.find(3, 4, 5)   # Returns an array
Read                                       Syntax

Tweet.find(2)         # Returns a single item

Tweet.find(3, 4, 5)   # Returns an array

Tweet.first           # Returns the first tweet
Read                                       Syntax

Tweet.find(2)         # Returns a single item

Tweet.find(3, 4, 5)   # Returns an array

Tweet.first           # Returns the first tweet

Tweet.last            # Returns the last tweet
Read                                       Syntax

Tweet.find(2)         # Returns a single item

Tweet.find(3, 4, 5)   # Returns an array

Tweet.first           # Returns the first tweet

Tweet.last            # Returns the last tweet

Tweet.all             # Returns all the tweets
Read                                       Syntax

Tweet.find(2)         # Returns a single item

Tweet.find(3, 4, 5)   # Returns an array

Tweet.first           # Returns the first tweet

Tweet.last            # Returns the last tweet

Tweet.all             # Returns all the tweets

Tweet.count           # Returns number of tweets
Read                                        Syntax

Tweet.find(2)          # Returns a single item

Tweet.find(3, 4, 5)    # Returns an array

Tweet.first            # Returns the first tweet

Tweet.last             # Returns the last tweet

Tweet.all              # Returns all the tweets

Tweet.count            # Returns number of tweets

Tweet.order(:zombie)   # All ordered by zombie
Read                                        Syntax

Tweet.find(2)          # Returns a single item

Tweet.find(3, 4, 5)    # Returns an array

Tweet.first            # Returns the first tweet

Tweet.last             # Returns the last tweet

Tweet.all              # Returns all the tweets

Tweet.count            # Returns number of tweets

Tweet.order(:zombie)   # All ordered by zombie

Tweet.limit(10)        # Only 10 tweets
Read                                           Syntax

Tweet.find(2)             # Returns a single item

Tweet.find(3, 4, 5)       # Returns an array

Tweet.first               # Returns the first tweet

Tweet.last                # Returns the last tweet

Tweet.all                 # Returns all the tweets

Tweet.count              # Returns number of tweets

Tweet.order(:zombie)      # All ordered by zombie

Tweet.limit(10)           # Only 10 tweets

Tweet.where(:zombie => "ash")   # Only tweets by Ash
Read                                           Syntax

Tweet.find(2)             # Returns a single item

Tweet.find(3, 4, 5)       # Returns an array

Tweet.first               # Returns the first tweet

Tweet.last                # Returns the last tweet

Tweet.all                 # Returns all the tweets

Tweet.count              # Returns number of tweets

Tweet.order(:zombie)      # All ordered by zombie

Tweet.limit(10)           # Only 10 tweets

Tweet.where(:zombie => "ash")   # Only tweets by Ash

Tweet.where(:zombie => "ash").order(:zombie).limit(10)
                  method chaining
Update                        Syntax

t = Tweet.find(3)
t.zombie = "EyeballChomper"
t.save
Update                                          Syntax

t = Tweet.find(3)
t.zombie = "EyeballChomper"
t.save


t = Tweet.find(2)
t.attributes = {
           :status => "Can I munch your eyeballs?",
           :zombie => "EyeballChomper"
           }
t.save
Update                                          Syntax

t = Tweet.find(3)
t.zombie = "EyeballChomper"
t.save


t = Tweet.find(2)
t.attributes = {
           :status => "Can I munch your eyeballs?",
           :zombie => "EyeballChomper"
           }
t.save


t = Tweet.find(2)
t.update_attributes(
           :status => "Can I munch your eyeballs?",
           :zombie => "EyeballChomper"
           )
Delete               Syntax


 t = Tweet.find(2)
 t.destroy
Delete                   Syntax


 t = Tweet.find(2)
 t.destroy


 Tweet.find(2).destroy
Delete                   Syntax


 t = Tweet.find(2)
 t.destroy


 Tweet.find(2).destroy


 Tweet.destroy_all
Zombie
             http://railsforzombies.org
      Stop when you reach the video for Lab 2

   Don’t worry about watching any of the videos

Download the slides so you can remember the syntax
An Introduction to
                      Rails
                      Episode #2




This content is available free on   created by
http://RailsForZombies.org
Chapter 2
     Models taste like chicken
Model
 s
Model
t = Tweet.find(3)
    Tweet            s
Model
t = Tweet.find(3)
    Tweet                                                     s




tweets
 id                     status                      zombie
  1   Where can I get a good bite to eat?         Ash
  2   My left arm is missing, but I don't care.   Bob
  3   I just ate some delicious brains.           Jim
  4   OMG, my fingers turned green. #FML           Ash
Model
t = Tweet.find(3)
    Tweet                                                     s



             ?
tweets
 id                     status                      zombie
  1   Where can I get a good bite to eat?         Ash
  2   My left arm is missing, but I don't care.   Bob
  3   I just ate some delicious brains.           Jim
  4   OMG, my fingers turned green. #FML           Ash
Model
t = Tweet.find(3)
    Tweet                                                     s

                         app/models/tweet.rb
                          class Tweet < ActiveRecord::Base

                          end



tweets
 id                     status                      zombie
  1   Where can I get a good bite to eat?         Ash
  2   My left arm is missing, but I don't care.   Bob
  3   I just ate some delicious brains.           Jim
  4   OMG, my fingers turned green. #FML           Ash
Model
         Tweet                                                s

                   app/models/tweet.rb
                    class Tweet < ActiveRecord::Base

                    end



tweets
 id                     status                      zombie
  1   Where can I get a good bite to eat?         Ash
  2   My left arm is missing, but I don't care.   Bob
  3   I just ate some delicious brains.           Jim
  4   OMG, my fingers turned green. #FML           Ash
Model
         Tweet                                                s

                   app/models/tweet.rb
                    class Tweet < ActiveRecord::Base

                    end



tweets
 id                     status                      zombie
  1   Where can I get a good bite to eat?         Ash
  2   My left arm is missing, but I don't care.   Bob
  3   I just ate some delicious brains.           Jim
  4   OMG, my fingers turned green. #FML           Ash
Model
         Tweet                                                s

                   app/models/tweet.rb
                    class Tweet < ActiveRecord::Base

                    end

               Maps the class to the
tweets                table
 id                     status                      zombie
  1   Where can I get a good bite to eat?         Ash
  2   My left arm is missing, but I don't care.   Bob
  3   I just ate some delicious brains.           Jim
  4   OMG, my fingers turned green. #FML           Ash
Model
         Tweet                                                s

                   app/models/tweet.rb
                    class Tweet < ActiveRecord::Base

                    end

               Maps the class to the
tweets                table
 id                     status                      zombie
  1   Where can I get a good bite to eat?         Ash
  2   My left arm is missing, but I don't care.   Bob
  3   I just ate some delicious brains.           Jim
  4   OMG, my fingers turned green. #FML           Ash
Model
app/models/tweet.rb
 class Tweet < ActiveRecord::Base                              s
 end




tweets
 id                      status                      zombie
  1    Where can I get a good bite to eat?         Ash
  2    My left arm is missing, but I don't care.   Bob
  3    I just ate some delicious brains.           Jim
  4    OMG, my fingers turned green. #FML           Ash
Model
app/models/tweet.rb
 class Tweet < ActiveRecord::Base                              s
 end



                                      t = Tweet.find(3)




tweets
 id                      status                      zombie
  1    Where can I get a good bite to eat?         Ash
  2    My left arm is missing, but I don't care.   Bob
  3    I just ate some delicious brains.           Jim
  4    OMG, my fingers turned green. #FML           Ash
Model
app/models/tweet.rb
 class Tweet < ActiveRecord::Base                              s
 end



                                      t = Tweet.find(3)


                                               class
tweets
 id                      status                      zombie
  1    Where can I get a good bite to eat?         Ash
  2    My left arm is missing, but I don't care.   Bob
  3    I just ate some delicious brains.           Jim
  4    OMG, my fingers turned green. #FML           Ash
Model
app/models/tweet.rb
 class Tweet < ActiveRecord::Base                              s
 end



                                      t = Tweet.find(3)


                                               class
tweets
 id                      status                      zombie
  1    Where can I get a good bite to eat?         Ash
  2    My left arm is missing, but I don't care.   Bob
  3    I just ate some delicious brains.           Jim
  4    OMG, my fingers turned green. #FML           Ash
Model
 app/models/tweet.rb
 class Tweet < ActiveRecord::Base                              s
 end



instance of Tweet                     t = Tweet.find(3)
          Tweet #3


                                               class
tweets
  id                     status                      zombie
   1   Where can I get a good bite to eat?         Ash
   2   My left arm is missing, but I don't care.   Bob
   3   I just ate some delicious brains.           Jim
   4   OMG, my fingers turned green. #FML           Ash
Validations?
id                     status                      zombie
 1   Where can I get a good bite to eat?         Ash
 2   My left arm is missing, but I don't care.   Bob
 3   I just ate some delicious brains.           Jim
 4   OMG, my fingers turned green. #FML           Ash
Validations?
id                     status                      zombie
 1   Where can I get a good bite to eat?         Ash
 2   My left arm is missing, but I don't care.   Bob
 3   I just ate some delicious brains.           Jim
 4   OMG, my fingers turned green. #FML           Ash




t = Tweet.new
t.save
Validations?
id                     status                      zombie
 1   Where can I get a good bite to eat?         Ash
 2   My left arm is missing, but I don't care.   Bob
 3   I just ate some delicious brains.           Jim
 4   OMG, my fingers turned green. #FML           Ash
 5




t = Tweet.new
t.save
Valida
                                           tio
app/models/tweet.rb                   ns
 class Tweet < ActiveRecord::Base




end
Valida
                                           tio
app/models/tweet.rb                   ns
 class Tweet < ActiveRecord::Base

  validates_presence_of :status

end
Valida
                                                            tio
app/models/tweet.rb                                    ns
 class Tweet < ActiveRecord::Base

   validates_presence_of :status

 end

> t = Tweet.new
          => #<Tweet id: nil, status: nil, zombie: nil>
Valida
                                                            tio
app/models/tweet.rb                                    ns
 class Tweet < ActiveRecord::Base

   validates_presence_of :status

 end

> t = Tweet.new
          => #<Tweet id: nil, status: nil, zombie: nil>
> t.save
          => false
Valida
                                                             tio
app/models/tweet.rb                                     ns
 class Tweet < ActiveRecord::Base

   validates_presence_of :status

 end

> t = Tweet.new
           => #<Tweet id: nil, status: nil, zombie: nil>
> t.save
           => false
> t.errors
           => {:status=>["can't be blank"]}
Valida
                                                              tio
app/models/tweet.rb                                      ns
 class Tweet < ActiveRecord::Base

   validates_presence_of :status

 end

> t = Tweet.new
            => #<Tweet id: nil, status: nil, zombie: nil>
> t.save
            => false
> t.errors
            => {:status=>["can't be blank"]}
> t.errors[:status]
            => "can't be blank"
Valida
       tio
  ns
Valida
                                                tio
validates_presence_of :status              ns
validates_numericality_of :fingers

validates_uniqueness_of :toothmarks

validates_confirmation_of :password

validates_acceptance_of :zombification

validates_length_of :password, :minimum => 3

validates_format_of :email, :with => /regex/i

validates_inclusion_of :age, :in => 21..99

validates_exclusion_of :age, :in => 0...21,
             :message => “Sorry you must be over 21”
Valida
       tio
  ns
te alidation                 Valida
   Attribu V                                  tio
validates :status, :presence => true
                                         ns
te alidation                            Valida
   Attribu V                                             tio
validates :status, :presence => true
                                                    ns
validates :status, :length => { :minimum => 3 }
te alidation                             Valida
   Attribu V                                              tio
validates :status, :presence => true
                                                     ns
validates :status, :length => { :minimum => 3 }




validates :status, :presence => true, :length => { :minimum => 3 }
te alidation                             Valida
   Attribu V                                              tio
validates :status, :presence => true
                                                     ns
validates :status, :length => { :minimum => 3 }




validates :status, :presence => true, :length => { :minimum => 3 }


:presence => true
:uniqueness => true
:numericality => true
:length => { :minimum => 0, :maximum => 2000 }
:format => { :with => /.*/ }
:inclusion => { :in => [1,2,3] }
:exclusion => { :in => [1,2,3] }
:acceptance => true
:confirmation => true
el a ti o nship s




    Because they always travel in packs
Relatio
tweets
                                                             nship
 id                     status                      zombie
  1   Where can I get a good bite to eat?         Ash
  2   My left arm is missing, but I don't care.   Bob
  3   I just ate some delicious brains.           Jim
  4   OMG, my fingers turned green. #FML           Ash
Relatio
tweets
                                                             nship
 id                     status                      zombie
  1   Where can I get a good bite to eat?         Ash
  2   My left arm is missing, but I don't care.   Bob
  3   I just ate some delicious brains.           Jim
  4   OMG, my fingers turned green. #FML           Ash
Relatio
tweets
                                                     nship
 id                     status
  1   Where can I get a good bite to eat?
  2   My left arm is missing, but I don't care.
  3   I just ate some delicious brains.
  4   OMG, my fingers turned green. #FML
Relatio
tweets
                                                     nship
 id                     status
  1   Where can I get a good bite to eat?
  2   My left arm is missing, but I don't care.
  3   I just ate some delicious brains.
  4   OMG, my fingers turned green. #FML




zombies
 id      name                 graveyard
 1    Ash        Glen Haven Memorial Cemetery
 2    Bob        Chapel Hill Cemetery
 3    Jim        My Father’s Basement
Relatio
tweets
                                                     nship
 id                     status
  1   Where can I get a good bite to eat?
  2   My left arm is missing, but I don't care.
  3   I just ate some delicious brains.
  4   OMG, my fingers turned green. #FML




zombies
 id      name                 graveyard
 1    Ash        Glen Haven Memorial Cemetery
 2    Bob        Chapel Hill Cemetery
 3    Jim        My Father’s Basement
Relatio
tweets
                                                                 nship
id                         status                    zombie_id
 1       Where can I get a good bite to eat?            1
 2       My left arm is missing, but I don't care.      2
 3       I just ate some delicious brains.              3
 4       OMG, my fingers turned green. #FML              1




zombies
 id           name                   graveyard
     1     Ash          Glen Haven Memorial Cemetery
     2     Bob          Chapel Hill Cemetery
     3     Jim          My Father’s Basement
Relatio
tweets
                                                                 nship
id                         status                    zombie_id
 1       Where can I get a good bite to eat?            1
 2       My left arm is missing, but I don't care.      2
 3       I just ate some delicious brains.              3
 4       OMG, my fingers turned green. #FML              1




zombies
 id           name                   graveyard
     1     Ash          Glen Haven Memorial Cemetery
     2     Bob          Chapel Hill Cemetery
     3     Jim          My Father’s Basement
Relatio
tweets
                                                                 nship
id                         status                    zombie_id
 1       Where can I get a good bite to eat?            1
 2       My left arm is missing, but I don't care.      2
 3       I just ate some delicious brains.              3
 4       OMG, my fingers turned green. #FML              1
5 Your eyelids taste like bacon.                        2




zombies
 id           name                   graveyard
     1     Ash          Glen Haven Memorial Cemetery
     2     Bob          Chapel Hill Cemetery
     3     Jim          My Father’s Basement
Relatio
tweets
                                                                 nship
id                         status                    zombie_id
 1       Where can I get a good bite to eat?            1
 2       My left arm is missing, but I don't care.      2
 3       I just ate some delicious brains.              3
 4       OMG, my fingers turned green. #FML              1
5 Your eyelids taste like bacon.                        2




zombies
 id           name                   graveyard
     1     Ash          Glen Haven Memorial Cemetery
     2     Bob          Chapel Hill Cemetery
     3     Jim          My Father’s Basement
Relatio
tweets
                                                                 nship
id                         status                    zombie_id
 1       Where can I get a good bite to eat?            1
 2       My left arm is missing, but I don't care.      2
 3       I just ate some delicious brains.              3
 4       OMG, my fingers turned green. #FML              1
5 Your eyelids taste like bacon.                        2




zombies
 id           name                   graveyard
     1     Ash          Glen Haven Memorial Cemetery
     2     Bob          Chapel Hill Cemetery
     3     Jim          My Father’s Basement
tweets
id                  status                    zombie_id
1 Where can I get a good bite to eat?            1
2 My left arm is missing, but I don't care.      2
3 I just ate some delicious brains.              3
4 OMG, my fingers turned green. #FML              1



     zombies
     id     name                  graveyard
     1    Ash         Glen Haven Memorial Cemetery
     2    Bob         Chapel Hill Cemetery
     3    Jim         My Father’s Basement
A Tweet




          tweets
          id                  status                    zombie_id
          1 Where can I get a good bite to eat?            1
          2 My left arm is missing, but I don't care.      2
          3 I just ate some delicious brains.              3
          4 OMG, my fingers turned green. #FML              1



               zombies
               id     name                  graveyard
               1    Ash         Glen Haven Memorial Cemetery
               2    Bob         Chapel Hill Cemetery
               3    Jim         My Father’s Basement
A Tweet belongs to




           tweets
           id                   status                    zombie_id
            1 Where can I get a good bite to eat?            1
            2 My left arm is missing, but I don't care.      2
            3 I just ate some delicious brains.              3
            4 OMG, my fingers turned green. #FML              1



                zombies
                id      name                  graveyard
                 1   Ash          Glen Haven Memorial Cemetery
                 2   Bob          Chapel Hill Cemetery
                 3   Jim          My Father’s Basement
A Tweet belongs to a Zombie




           tweets
           id                  status                    zombie_id
           1 Where can I get a good bite to eat?            1
           2 My left arm is missing, but I don't care.      2
           3 I just ate some delicious brains.              3
           4 OMG, my fingers turned green. #FML              1



                zombies
                id     name                  graveyard
                1    Ash         Glen Haven Memorial Cemetery
                2    Bob         Chapel Hill Cemetery
                3    Jim         My Father’s Basement
A Tweet belongs to a Zombie
app/models/tweet.rb
 class Tweet < ActiveRecord::Base




 end



              tweets
              id                  status                    zombie_id
              1 Where can I get a good bite to eat?            1
              2 My left arm is missing, but I don't care.      2
              3 I just ate some delicious brains.              3
              4 OMG, my fingers turned green. #FML              1



                   zombies
                   id     name                  graveyard
                   1    Ash         Glen Haven Memorial Cemetery
                   2    Bob         Chapel Hill Cemetery
                   3    Jim         My Father’s Basement
A Tweet belongs to a Zombie
app/models/tweet.rb
 class Tweet < ActiveRecord::Base

   belongs_to :zombie

 end




Singular tweets
         id                       status                    zombie_id
              1 Where can I get a good bite to eat?            1
              2 My left arm is missing, but I don't care.      2
              3 I just ate some delicious brains.              3
              4 OMG, my fingers turned green. #FML              1



                 zombies
                  id      name                  graveyard
                   1   Ash          Glen Haven Memorial Cemetery
                   2   Bob          Chapel Hill Cemetery
                   3   Jim          My Father’s Basement
A Tweet belongs to a Zombie                         A Zombie
app/models/tweet.rb
 class Tweet < ActiveRecord::Base

   belongs_to :zombie

 end




Singular tweets
         id                       status                    zombie_id
              1 Where can I get a good bite to eat?            1
              2 My left arm is missing, but I don't care.      2
              3 I just ate some delicious brains.              3
              4 OMG, my fingers turned green. #FML              1



                 zombies
                  id      name                  graveyard
                   1   Ash          Glen Haven Memorial Cemetery
                   2   Bob          Chapel Hill Cemetery
                   3   Jim          My Father’s Basement
A Tweet belongs to a Zombie                         A Zombie has many
app/models/tweet.rb
 class Tweet < ActiveRecord::Base

   belongs_to :zombie

 end




Singular tweets
         id                       status                    zombie_id
              1 Where can I get a good bite to eat?            1
              2 My left arm is missing, but I don't care.      2
              3 I just ate some delicious brains.              3
              4 OMG, my fingers turned green. #FML              1



                 zombies
                  id      name                  graveyard
                   1   Ash          Glen Haven Memorial Cemetery
                   2   Bob          Chapel Hill Cemetery
                   3   Jim          My Father’s Basement
A Tweet belongs to a Zombie                         A Zombie has many Tweets
app/models/tweet.rb
 class Tweet < ActiveRecord::Base

   belongs_to :zombie

 end




Singular tweets
         id                       status                    zombie_id
              1 Where can I get a good bite to eat?            1
              2 My left arm is missing, but I don't care.      2
              3 I just ate some delicious brains.              3
              4 OMG, my fingers turned green. #FML              1



                 zombies
                  id      name                  graveyard
                   1   Ash          Glen Haven Memorial Cemetery
                   2   Bob          Chapel Hill Cemetery
                   3   Jim          My Father’s Basement
A Tweet belongs to a Zombie                         A Zombie has many Tweets
app/models/tweet.rb                                 app/models/zombie.rb
 class Tweet < ActiveRecord::Base                   class Zombie < ActiveRecord::Base

   belongs_to :zombie

 end                                                end




Singular tweets
         id                       status                    zombie_id
              1 Where can I get a good bite to eat?            1
              2 My left arm is missing, but I don't care.      2
              3 I just ate some delicious brains.              3
              4 OMG, my fingers turned green. #FML              1



                 zombies
                  id      name                  graveyard
                   1   Ash          Glen Haven Memorial Cemetery
                   2   Bob          Chapel Hill Cemetery
                   3   Jim          My Father’s Basement
A Tweet belongs to a Zombie                         A Zombie has many Tweets
app/models/tweet.rb                                 app/models/zombie.rb
 class Tweet < ActiveRecord::Base                   class Zombie < ActiveRecord::Base

   belongs_to :zombie                                   has_many :tweets

 end                                                end


                                                                        Plural
Singular tweets
         id                       status                    zombie_id
              1 Where can I get a good bite to eat?            1
              2 My left arm is missing, but I don't care.      2
              3 I just ate some delicious brains.              3
              4 OMG, my fingers turned green. #FML              1



                 zombies
                  id      name                  graveyard
                   1   Ash          Glen Haven Memorial Cemetery
                   2   Bob          Chapel Hill Cemetery
                   3   Jim          My Father’s Basement
Relatio
                                        nship
A Tweet belongs to a Zombie
Relatio
                                                                 nship
  A Tweet belongs to a Zombie
> z = Zombie.find(2)
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">
Relatio
                                                                     nship
  A Tweet belongs to a Zombie
> z = Zombie.find(2)
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z)
=> #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2>
Relatio
                                                                     nship
  A Tweet belongs to a Zombie
> z = Zombie.find(2)
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z)
=> #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2>

> t.zombie
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">
Relatio
                                                                     nship
  A Tweet belongs to a Zombie
> z = Zombie.find(2)
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z)
=> #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2>

> t.zombie
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t.zombie.name
=> "Bob"
Relatio
                                                                     nship
  A Tweet belongs to a Zombie
> z = Zombie.find(2)
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z)
=> #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2>

> t.zombie
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t.zombie.name
=> "Bob"

> ash = Zombie.find(1)
 => #<Zombie id: 1, name: "Ash", graveyard: "Glen Haven Cemetery">
Relatio
                                                                     nship
  A Tweet belongs to a Zombie
> z = Zombie.find(2)
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z)
=> #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2>

> t.zombie
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t.zombie.name
=> "Bob"

> ash = Zombie.find(1)
 => #<Zombie id: 1, name: "Ash", graveyard: "Glen Haven Cemetery">

> ash.tweets.count
 => 4
Relatio
                                                                     nship
  A Tweet belongs to a Zombie
> z = Zombie.find(2)
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z)
=> #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2>

> t.zombie
=> #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">

> t.zombie.name
=> "Bob"

> ash = Zombie.find(1)
 => #<Zombie id: 1, name: "Ash", graveyard: "Glen Haven Cemetery">

> ash.tweets.count
 => 4


> ash.tweets
 => [#<Tweet id: 1, status: "Where can I get a good bite to eat?", zombie_id: 1>,
#<Tweet id: 4, status: "OMG, my fingers turned green. #FML", zombie_id: 1>]
Zombie
An Introduction to
                      Rails
                       Episode #




This content is available free on   created by
http://RailsForZombies.org
Chapter 3
 The View ain’t always pretty

                      I’m so gonna
                      eat his brains
Vie
Our Application Stack   ws
Vie
Our Application Stack       ws




             4 Components
Vie
Our Application Stack       ws




   Models
             4 Components
Vie
Our Application Stack       ws




     Views



   Models
             4 Components
Views
Views

zombie_twitter
   app
Views

zombie_twitter
   app
       views
Views

zombie_twitter
   app
       views
          zombies
           tweets
Views

zombie_twitter
   app
       views
          zombies
           tweets
               index.html.erb
               show.html.erb
Views

zombie_twitter
   app
       views
          zombies
                        List all tweets
           tweets
               index.html.erb
               show.html.erb
Views

zombie_twitter
   app
       views
          zombies
                        List all tweets
           tweets
               index.html.erb
                                View a tweet
               show.html.erb
Views
                    Edible Rotting Bodies

zombie_twitter
   app
       views
          zombies
                        List all tweets
           tweets
               index.html.erb
                                View a tweet
               show.html.erb
Views
                    Edible Rotting Bodies
                     Embedded Ruby
zombie_twitter
                           Ruby inside HTML
   app
       views
          zombies
                        List all tweets
           tweets
               index.html.erb
                                View a tweet
               show.html.erb
Show a tweet
Show a tweet
Show a tweet
<% ... %>
 Evaluate Ruby
Show a tweet
<% ... %>
 Evaluate Ruby
<%= ... %>
Eval and print result
Show a tweet
<% ... %>
  Evaluate Ruby
 <%= ... %>
Eval and print result
/app/views/tweets/show.html.erb
 <!DOCTYPE html>
 <html>
  <head><title>Twitter for Zombies</title></head>
 <body>
   <img src="/images/twitter.png" />




 </body></html>
Show a tweet
<% ... %>
  Evaluate Ruby
 <%= ... %>
Eval and print result
/app/views/tweets/show.html.erb
 <!DOCTYPE html>
 <html>
  <head><title>Twitter for Zombies</title></head>
 <body>
   <img src="/images/twitter.png" />

   <% tweet = Tweet.find(1) %>

   <h1><%= tweet.status %></h1>

   <p>Posted by <%= tweet.zombie.name %></p>

 </body></html>
Show a tweet
<% ... %>
  Evaluate Ruby
 <%= ... %>
Eval and print result
/app/views/tweets/show.html.erb
 <!DOCTYPE html>
 <html>
  <head><title>Twitter for Zombies</title></head>
 <body>
   <img src="/images/twitter.png" />
                                               FYI, This code
   <% tweet = Tweet.find(1) %>
                                               sucks a little..
   <h1><%= tweet.status %></h1>                     (for 2 reasons)

   <p>Posted by <%= tweet.zombie.name %></p>

 </body></html>
Show a tweet
<% ... %>
  Evaluate Ruby
 <%= ... %>
Eval and print result
/app/views/tweets/show.html.erb
 <!DOCTYPE html>
 <html>
  <head><title>Twitter for Zombies</title></head>
 <body>
   <img src="/images/twitter.png" />

   <% tweet = Tweet.find(1) %>

   <h1><%= tweet.status %></h1>

   <p>Posted by <%= tweet.zombie.name %></p>

 </body></html>
Show a tweet
          /app/views/layouts/
          application.html.erb
<!DOCTYPE html>
<html>
 <head><title>Twitter for Zombies</title></head>
<body>
  <img src="/images/twitter.png" />




 </body></html>


/app/views/tweets/show.html.erb
 <% tweet = Tweet.find(1) %>

 <h1><%= tweet.status %></h1>

 <p>Posted by <%= tweet.zombie.name %></p>
Show a tweet
          /app/views/layouts/
          application.html.erb
<!DOCTYPE html>
<html>
 <head><title>Twitter for Zombies</title></head>
<body>
  <img src="/images/twitter.png" />

  <%= yield %>

 </body></html>


/app/views/tweets/show.html.erb
 <% tweet = Tweet.find(1) %>

 <h1><%= tweet.status %></h1>

 <p>Posted by <%= tweet.zombie.name %></p>
Views
zombie_twitter
   app
       views




          zombies
                        List all tweets
           tweets
               index.html.erb
                                View a tweet
               show.html.erb
Views
zombie_twitter
   app
       views
           layouts


          zombies
                        List all tweets
           tweets
               index.html.erb
                                View a tweet
               show.html.erb
Views
zombie_twitter
   app
       views
                     The main layout
           layouts
               application.html.erb
          zombies
                        List all tweets
           tweets
               index.html.erb
                                View a tweet
               show.html.erb
Additional Layout Components
          /app/views/layouts/
          application.html.erb
<!DOCTYPE html>
<html>
<head>
  <title>Twitter for Zombies</title>
</head>
<body>
  <img src="/images/twitter.png" />

  <%= yield %>

</body></html>
Additional Layout Components
          /app/views/layouts/
          application.html.erb
<!DOCTYPE html>
<html>
<head>
  <title>Twitter for Zombies</title>




</head>
<body>
  <img src="/images/twitter.png" />

  <%= yield %>

</body></html>
Additional Layout Components
          /app/views/layouts/
          application.html.erb
<!DOCTYPE html>
<html>
<head>
  <title>Twitter for Zombies</title>
  <%= stylesheet_link_tag :all %>



</head>
<body>
  <img src="/images/twitter.png" />

  <%= yield %>

</body></html>
Additional Layout Components
          /app/views/layouts/
          application.html.erb
<!DOCTYPE html>
<html>
<head>
  <title>Twitter for Zombies</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>

</head>
<body>
  <img src="/images/twitter.png" />

  <%= yield %>

</body></html>
Additional Layout Components
          /app/views/layouts/
          application.html.erb
<!DOCTYPE html>
<html>
<head>
  <title>Twitter for Zombies</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
</head>
<body>
  <img src="/images/twitter.png" />

  <%= yield %>

</body></html>
Additional Layout Components
 <%= stylesheet_link_tag :all %>




 <%= javascript_include_tag :defaults %>




 <%= csrf_meta_tag %>
Additional Layout Components
 <%= stylesheet_link_tag :all %>
                                      Includ
                                     styles  e all
                                           heets




 <%= javascript_include_tag :defaults %>




 <%= csrf_meta_tag %>
Additional Layout Components
 <%= stylesheet_link_tag :all %>
                                      Includ
      zombie_twitter                 styles  e all
         public
                                           heets
            stylesheets




 <%= javascript_include_tag :defaults %>




 <%= csrf_meta_tag %>
Additional Layout Components
 <%= stylesheet_link_tag :all %>
                                                    Includ
        zombie_twitter                             styles  e all
             public
                                                         heets
                 stylesheets

Renders
<link href="/stylesheets/scaffold.css" media="screen" rel="stylesheet" type="text/css" />




 <%= javascript_include_tag :defaults %>




  <%= csrf_meta_tag %>
Additional Layout Components
 <%= stylesheet_link_tag :all %>


 <%= javascript_include_tag :defaults %>




 <%= csrf_meta_tag %>
Additional Layout Components
 <%= stylesheet_link_tag :all %>


 <%= javascript_include_tag :defaults %>

                                   Includ
                                            e d ef
                                                  ault J
                                                         S




 <%= csrf_meta_tag %>
Additional Layout Components
 <%= stylesheet_link_tag :all %>


 <%= javascript_include_tag :defaults %>

                                   Includ
    zombie_twitter                          e d ef
                                                  ault J
        public                                           S
           javascripts




 <%= csrf_meta_tag %>
Additional Layout Components
 <%= stylesheet_link_tag :all %>


 <%= javascript_include_tag :defaults %>

                                         Includ
      zombie_twitter                                  e d ef
                                                            ault J
            public                                                 S
                javascripts

Renders
<script                                      Proto
          src="/javascripts/prototype.js" type="text/javascript"></script>
<script                                            type
          src="/javascripts/effects.js" type="text/javascript"></script>
                                                        Javas
<script
                                                 Fram        c r ip t
          src="/javascripts/dragdrop.js" type="text/javascript"></script>
<script
<script                                               ework
          src="/javascripts/controls.js" type="text/javascript"></script>
          src="/javascripts/rails.js" type="text/javascript"></script>
<script   src="/javascripts/application.js" type="text/javascript"></script>


  <%= csrf_meta_tag %>
Additional Layout Components
 <%= stylesheet_link_tag :all %>


 <%= javascript_include_tag :defaults %>


 <%= csrf_meta_tag %>
Additional Layout Components
     <%= stylesheet_link_tag :all %>


     <%= javascript_include_tag :defaults %>


      <%= csrf_meta_tag %>



Zombie Hacker
  <form  Site
        target="http://yoursite.co
                                   m">
                                         Think   Your Site
                                                comm
                                               spam ent
Additional Layout Components
     <%= stylesheet_link_tag :all %>


     <%= javascript_include_tag :defaults %>


      <%= csrf_meta_tag %>



Zombie Hacker
  <form  Site
        target="http://yoursite.co
                                   m">
                                               Think          Your Site
                                                          comm
   Renders                                               spam ent
     <meta name="csrf-param" content="authenticity_token"/>
     <meta name="csrf-token" content="I+d..jI="/>



         Automatically adds this to forms
Root path and images
Root path and images
 http://ZombieTwitter.com/[something]
Root path and images
 http://ZombieTwitter.com/[something]

    zombie_twitter                          lic
                                          ub to
       public                          /p
                                   in e go
                             xi sts rwis
         stylesheets
                        I f e othe
         javascripts
                          e it,    Ra ils
          images       us

  Example
   <img src="/images/twitter.png" />
Adding a Link
Adding a Link
/app/views/tweets/show.html.erb
 ...
 <p>Posted by <%= tweet.zombie.name %></p>
Adding a Link
/app/views/tweets/show.html.erb
                                                  bi ea
 ...

                                             ez om
                                           ak ink
 <p>Posted by <%= tweet.zombie.name %></p>

                                         M    l
Adding a Link
/app/views/tweets/show.html.erb
                                                  bi ea
 ...

                                             ez om
                                           ak ink
 <p>Posted by <%= tweet.zombie.name %></p>

                                         M    l
<%=                                               %>
Adding a Link
/app/views/tweets/show.html.erb
                                                  bi ea
 ...

                                             ez om
                                           ak ink
 <p>Posted by <%= tweet.zombie.name %></p>

                                         M    l
<%= link_to                                       %>
Adding a Link
/app/views/tweets/show.html.erb
                                                  bi ea
 ...

                                             ez om
                                           ak ink
 <p>Posted by <%= tweet.zombie.name %></p>

                                         M    l
<%= link_to tweet.zombie.name                     %>

              Link Text
Adding a Link
/app/views/tweets/show.html.erb
                                                  bi ea
 ...

                                             ez om
                                           ak ink
 <p>Posted by <%= tweet.zombie.name %></p>

                                         M    l
<%= link_to tweet.zombie.name , zombie_path(tweet.zombie)   %>

              Link Text          Link Path (URL)
Adding a Link
/app/views/tweets/show.html.erb
                                                  bi ea
 ...

                                             ez om
                                           ak ink
 <p>Posted by <%= tweet.zombie.name %></p>

                                         M    l
<%= link_to tweet.zombie.name , zombie_path(tweet.zombie)   %>

              Link Text          Link Path (URL)

     Renders            <a href="/zombies/1">Ash</a>
Adding a Link
/app/views/tweets/show.html.erb
                                                  bi ea
 ...

                                             ez om
                                           ak ink
 <p>Posted by <%= tweet.zombie.name %></p>

                                         M    l
<%= link_to tweet.zombie.name , zombie_path(tweet.zombie)   %>

              Link Text          Link Path (URL)

     Renders            <a href="/zombies/1">Ash</a>


We can also write as
    <%= link_to tweet.zombie.name, tweet.zombie %>

                    Link Text          Object to Show
Method
   link_to                      with it?
                       y ou use
               ons can
    W hat opti
Method
   link_to                      with it?
                       y ou use
               ons can
    W hat opti

    1. Look in the source
Method
   link_to                      with it?
                       y ou use
               ons can
    W hat opti

    1. Look in the source
Command Line
Method
   link_to                      with it?
                       y ou use
               ons can
    W hat opti

    1. Look in the source
Command Line
   git clone http://github.com/rails/rails.git
Method
   link_to                      with it?
                       y ou use
               ons can
    W hat opti

    1. Look in the source
Command Line
   git clone http://github.com/rails/rails.git
 cd rails
Method
   link_to                      with it?
                       y ou use
               ons can
    W hat opti

    1. Look in the source
Command Line
   git clone http://github.com/rails/rails.git
 cd rails


  Open your editor and search for “def link_to”
Method
   link_to                       with it?
                        y ou use
               ions can
    W hat op t

              2. Look at
         api.rubyonrails.org
              (and search for link_to)
http://
Method
   link_to                       with it?
                        y ou use
               ions can
    W hat op t
Method
   link_to                       with it?
                        y ou use
               ions can
    W hat op t

   3. API Dock
          (online Ruby and Rails docs)
         http://apidock.com/rails
Method
                                   with it?
   link_to
                          y ou use
                 ions can
      W hat op t
Method
                                   with it?
   link_to
                          y ou use
                 ions can
      W hat op t
4. Rails Searchable API Doc
            (local download or online)

            http://railsapi.com/
http://railsapi.com/
<%= link_to @tweet.zombie.name, @tweet.zombie, :confirm => "Are you sure?" %>
<%= link_to @tweet.zombie.name, @tweet.zombie, :confirm => "Are you sure?" %>
Views
zombie_twitter
   app
       views
                     The main layout
           layouts
               application.html.erb
          zombies
                        List all tweets
           tweets
               index.html.erb
                                View a tweet
               show.html.erb
Views
List Tweets
Views
List Tweets
Views
     List Tweets

/app/views/tweets/index.html.erb
Views
      List Tweets

/app/views/tweets/index.html.erb
  <h1>Listing tweets</h1>

  <table>
    <tr>
      <th>Status</th>
      <th>Zombie</th>
    </tr>
Views
      List Tweets

/app/views/tweets/index.html.erb
  <h1>Listing tweets</h1>

  <table>
    <tr>
      <th>Status</th>
      <th>Zombie</th>
    </tr>

  <% Tweet.all.each do |tweet| %>
Views
      List Tweets

/app/views/tweets/index.html.erb
  <h1>Listing tweets</h1>

  <table>
    <tr>
      <th>Status</th>
      <th>Zombie</th>
    </tr>

  <% Tweet.all.each do |tweet| %>
    <tr>
      <td><%=
      <td><%=
    </tr>
  <% end %>
  </table>
Views
      List Tweets

/app/views/tweets/index.html.erb
  <h1>Listing tweets</h1>

  <table>
    <tr>
      <th>Status</th>
      <th>Zombie</th>
    </tr>

  <% Tweet.all.each do |tweet| %>
    <tr>
      <td><%= tweet.status %></td>
      <td><%=
    </tr>
  <% end %>
  </table>
Views
      List Tweets

/app/views/tweets/index.html.erb
  <h1>Listing tweets</h1>

  <table>
    <tr>
      <th>Status</th>
      <th>Zombie</th>
    </tr>

  <% Tweet.all.each do |tweet| %>
    <tr>
      <td><%= tweet.status %></td>
      <td><%= tweet.zombie.name %></td>
    </tr>
  <% end %>
  </table>
Views
      List Tweets

/app/views/tweets/index.html.erb
  <h1>Listing tweets</h1>

  <table>
    <tr>
      <th>Status</th>
      <th>Zombie</th>
    </tr>                                 What they return
  <% Tweet.all.each do |tweet| %>         Tweet   class
    <tr>
      <td><%= tweet.status %></td>
      <td><%= tweet.zombie.name %></td>
    </tr>
  <% end %>
  </table>
Views
      List Tweets

/app/views/tweets/index.html.erb
  <h1>Listing tweets</h1>

  <table>
    <tr>
      <th>Status</th>
      <th>Zombie</th>
    </tr>                                 What they return
  <% Tweet.all.each do |tweet| %>         Tweet      class
    <tr>
      <td><%= tweet.status %></td>
      <td><%= tweet.zombie.name %></td>   Tweet.all array of tweets
    </tr>
  <% end %>
  </table>
Views
      List Tweets

/app/views/tweets/index.html.erb
  <h1>Listing tweets</h1>

  <table>
    <tr>
      <th>Status</th>
      <th>Zombie</th>
    </tr>                                 What they return
  <% Tweet.all.each do |tweet| %>         Tweet      class
    <tr>
      <td><%= tweet.status %></td>
      <td><%= tweet.zombie.name %></td>   Tweet.all array of tweets
    </tr>
  <% end %>                                tweet     single tweet
  </table>
Create Links                             Views
/app/views/tweets/index.html.erb
 <% Tweet.all.each do |tweet| %>
   <tr>
     <td><%= tweet.status %></td>
     <td><%= tweet.zombie.name %></td>
   </tr>
 <% end %>
Create Links                                        Views
/app/views/tweets/index.html.erb
  <% Tweet.all.each do |tweet| %>
    <tr>
      <td><%= link_to tweet.status, tweet %></td>
      <td><%= tweet.zombie.name %></td>
    </tr>
  <% end %>
Create Links                                                Views
/app/views/tweets/index.html.erb
  <% Tweet.all.each do |tweet| %>
    <tr>
      <td><%= link_to tweet.status, tweet %></td>
      <td><%= link_to tweet.zombie.name, tweet.zombie %></td>
    </tr>
  <% end %>
Empty Table?Views




<% Tweet.all.each do |tweet| %>
   <tr>
     <td><%= link_to tweet.status, tweet %></td>
     <td><%= link_to tweet.zombie.name, tweet.zombie %></td>
   </tr>
<% end %>
Empty Table?Views




<% Tweet.all.each do |tweet| %>
   <tr>
     <td><%= link_to tweet.status, tweet %></td>
     <td><%= link_to tweet.zombie.name, tweet.zombie %></td>
   </tr>
<% end %>
Empty Table?Views




<% Tweet.all.each do |tweet| %>
   <tr>
     <td><%= link_to tweet.status, tweet %></td>
     <td><%= link_to tweet.zombie.name, tweet.zombie %></td>
   </tr>
<% end %>
Empty Table?Views




<% Tweet.all.each do |tweet| %>
   ...
<% end %>
Empty Table?Views




<% tweets = Tweet.all %>

<%          .each do |tweet| %>
   ...
<% end %>
Empty Table?Views




<% tweets = Tweet.all %>

<% tweets.each do |tweet| %>
   ...
<% end %>
Empty Table?Views




<% tweets = Tweet.all %>

<% tweets.each do |tweet| %>
   ...
<% end %>



<% if tweets.size == 0 %>
   <em>No tweets found</em>
<% end %>
Empty Table?Views




<% tweets = Tweet.all %>

<% tweets.each do |tweet| %>
   ...
<% end %>



<% if tweets.empty? %>
   <em>No tweets found</em>
<% end %>
Empty Table?Views




<% tweets = Tweet.all %>

<% tweets.each do |tweet| %>
   ...
<% end %>



<% if tweets.empty? %>
   <em>No tweets found</em>
<% end %>
Edit & Delete Links?
Edit & Delete Links?
Edit & Delete Links?
 <% tweets.each do |tweet| %>
   <tr>
     <td><%= link_to tweet.status, tweet %></td>
     <td><%= link_to tweet.zombie.name, tweet.zombie %></td>



   </tr>
 <% end %>
Edit & Delete Links?
 <% tweets.each do |tweet| %>
   <tr>
     <td><%= link_to tweet.status, tweet %></td>
     <td><%= link_to tweet.zombie.name, tweet.zombie %></td>
     <td><%= link_to "Edit", edit_tweet_path(tweet) %></td>

   </tr>
 <% end %>
Edit & Delete Links?
 <% tweets.each do |tweet| %>
   <tr>
     <td><%= link_to tweet.status, tweet %></td>
     <td><%= link_to tweet.zombie.name, tweet.zombie %></td>
     <td><%= link_to "Edit", edit_tweet_path(tweet) %></td>
     <td><%= link_to "Delete", tweet, :method => :delete %></td>
   </tr>
 <% end %>
All links for Tweets
All links for Tweets
<%= link_to "<link text>", <code> %>
All links for Tweets
 <%= link_to "<link text>", <code> %>



Action            Code             The URL Generated
List all tweets   tweets_path      /tweets
New tweet form    new_tweet_path   /tweets/new
All links for Tweets
 <%= link_to "<link text>", <code> %>



Action            Code             The URL Generated
List all tweets   tweets_path      /tweets
New tweet form    new_tweet_path   /tweets/new
All links for Tweets
 <%= link_to "<link text>", <code> %>



Action            Code             The URL Generated
List all tweets   tweets_path      /tweets
New tweet form    new_tweet_path   /tweets/new
All links for Tweets
 <%= link_to "<link text>", <code> %>



Action            Code                The URL Generated
List all tweets   tweets_path         /tweets
New tweet form    new_tweet_path      /tweets/new


                                   These paths n
tweet = Tweet.find(1)                           eed a
                                         tweet
All links for Tweets
 <%= link_to "<link text>", <code> %>



Action              Code                   The URL Generated
List all tweets     tweets_path          /tweets
New tweet form      new_tweet_path       /tweets/new


                                     These paths n
tweet = Tweet.find(1)                                 eed a
                                           tweet
Action            Code                      The URL Generated
Show a tweet      tweet                          /tweets/1
Edit a tweet      edit_tweet_path(tweet)         /tweets/1/edit
Delete a tweet    tweet, :method => :delete /tweets/1
All links for Tweets
 <%= link_to "<link text>", <code> %>



Action              Code                   The URL Generated
List all tweets     tweets_path          /tweets
New tweet form      new_tweet_path       /tweets/new


                                     These paths n
tweet = Tweet.find(1)                                 eed a
                                           tweet
Action            Code                      The URL Generated
Show a tweet      tweet                          /tweets/1
Edit a tweet      edit_tweet_path(tweet)         /tweets/1/edit
Delete a tweet    tweet, :method => :delete /tweets/1
All links for Tweets
 <%= link_to "<link text>", <code> %>



Action              Code                   The URL Generated
List all tweets     tweets_path          /tweets
New tweet form      new_tweet_path       /tweets/new


                                     These paths n
tweet = Tweet.find(1)                                 eed a
                                           tweet
Action            Code                      The URL Generated
Show a tweet      tweet                          /tweets/1
Edit a tweet      edit_tweet_path(tweet)         /tweets/1/edit
Delete a tweet    tweet, :method => :delete /tweets/1
Zombie
An Introduction to
                      Rails
                       Episode #




This content is available free on   created by
http://RailsForZombies.org
Chapter 4    r ai ns
             b
             v
  Controllers must be eaten
Vie
Our Application Stack   ws
Vie
Our Application Stack       ws




     Views



   Models
             4 Components
Vie
Our Application Stack          ws




      Views

  Controllers

   Models
                4 Components
Show a tweet

/app/views/tweets/show.html.erb
 <!DOCTYPE html>
 <html>
  <head><title>Twitter for Zombies</title></head>
 <body>
   <img src="/images/twitter.png" />
                                               FYI, This code
  <% tweet = Tweet.find(1) %>
                                               sucks a little..
   <h1><%= tweet.status %></h1>                     (we’ll fix it later)

   <p>Posted by <%= tweet.zombie.name %></p>

 </body></html>
/app/views/tweets/show.html.erb
   <% tweet = Tweet.find(1) %>

   <h1><%= tweet.status %></h1>

   <p>Posted by <%= tweet.zombie.name %></p>
Request
                                               /tweets/1




/app/views/tweets/show.html.erb
   <% tweet = Tweet.find(1) %>

   <h1><%= tweet.status %></h1>

   <p>Posted by <%= tweet.zombie.name %></p>
Request
                                               /tweets/1




              Controller

/app/views/tweets/show.html.erb
   <% tweet = Tweet.find(1) %>

   <h1><%= tweet.status %></h1>

   <p>Posted by <%= tweet.zombie.name %></p>
zombie_twitter
        app                                     Request
            controllers                         /tweets/1
              tweets_controller.rb

/app/controllers/tweets_controller.rb


               Controller

 /app/views/tweets/show.html.erb
    <% tweet = Tweet.find(1) %>

    <h1><%= tweet.status %></h1>

    <p>Posted by <%= tweet.zombie.name %></p>
zombie_twitter
         app                                    Request
            controllers                          tweets
                                                /tweets/1
               tweets_controller.rb

                 tweets
/app/controllers/tweets_controller.rb


               Controller

 /app/views/tweets/show.html.erb
            tweets
    <% tweet = Tweet.find(1) %>

    <h1><%= tweet.status %></h1>

    <p>Posted by <%= tweet.zombie.name %></p>
Request
                                                /tweets/1

/app/controllers/tweets_controller.rb




 /app/views/tweets/show.html.erb
    <% tweet = Tweet.find(1) %>

    <h1><%= tweet.status %></h1>

    <p>Posted by <%= tweet.zombie.name %></p>
Request
                                                /tweets/1

/app/controllers/tweets_controller.rb
  class TweetsController < ApplicationController
        ...
  end




 /app/views/tweets/show.html.erb
    <% tweet = Tweet.find(1) %>

    <h1><%= tweet.status %></h1>

    <p>Posted by <%= tweet.zombie.name %></p>
Request
                                                /tweets/1

/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show

   end
 end




/app/views/tweets/show.html.erb
    <% tweet = Tweet.find(1) %>

    <h1><%= tweet.status %></h1>

    <p>Posted by <%= tweet.zombie.name %></p>
Request
                                                /tweets/1

/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show

   end
 end




/app/views/tweets/show.html.erb
                  show
    <% tweet = Tweet.find(1) %>

    <h1><%= tweet.status %></h1>

    <p>Posted by <%= tweet.zombie.name %></p>
Request
                                                /tweets/1

/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show

   end
 end




/app/views/tweets/show.html.erb
    <% tweet = Tweet.find(1) %>

    <h1><%= tweet.status %></h1>

    <p>Posted by <%= tweet.zombie.name %></p>
Request
                                               /tweets/1

/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     tweet = Tweet.find(1)
   end
 end




/app/views/tweets/show.html.erb
   <h1><%= tweet.status %></h1>

   <p>Posted by <%= tweet.zombie.name %></p>
Request
                                               /tweets/1

/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     tweet = Tweet.find(1)
   end
 end




/app/views/tweets/show.html.erb
   <h1><%= tweet.status %></h1>

   <p>Posted by <%= tweet.zombie.name %></p>
Request
                                               /tweets/1

/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     tweet = Tweet.find(1)
   end
 end




/app/views/tweets/show.html.erb
   <h1><%= tweet.status %></h1>

   <p>Posted by <%= tweet.zombie.name %></p>
Request
                                               /tweets/1

/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     tweet = Tweet.find(1)
   end
 end




/app/views/tweets/show.html.erb
                                             What about
   <h1><%= tweet.status %></h1>            variable scope?
   <p>Posted by <%= tweet.zombie.name %></p>
Instance Variable                                Request
                                                 /tweets/1
                @
/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
       tweet = Tweet.find(1)
   end
 end




/app/views/tweets/show.html.erb
   <h1><%=   tweet.status %></h1>

   <p>Posted by <%=   tweet.zombie.name %></p>
Instance Variable                                Request
                                                 /tweets/1
                @
/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     @ tweet = Tweet.find(1)
   end
 end




/app/views/tweets/show.html.erb
   <h1><%=   tweet.status %></h1>

   <p>Posted by <%=   tweet.zombie.name %></p>
Instance Variable                                Request
                                                 /tweets/1
                @
/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     @ tweet = Tweet.find(1)
   end
 end




/app/views/tweets/show.html.erb
   <h1><%= @ tweet.status %></h1>

   <p>Posted by <%=   tweet.zombie.name %></p>
Instance Variable                                Request
                                                 /tweets/1
                @
/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     @ tweet = Tweet.find(1)
   end
 end




/app/views/tweets/show.html.erb
   <h1><%= @ tweet.status %></h1>

   <p>Posted by <%= @ tweet.zombie.name %></p>
Render                                           Request
                                                 /tweets/1

/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     @ tweet = Tweet.find(1)
   end
 end




/app/views/tweets/status.html.erb
   <h1><%= @ tweet.status %></h1>

   <p>Posted by <%= @ tweet.zombie.name %></p>
Render                                           Request
                                                 /tweets/1

/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     @ tweet = Tweet.find(1)
   end
 end




/app/views/tweets/status.html.erb
   <h1><%= @ tweet.status %></h1>

   <p>Posted by <%= @ tweet.zombie.name %></p>
Render                                           Request
                                                 /tweets/1
/app/controllers/tweets_controller.rb
 class TweetsController < ApplicationController
   def show
     @ tweet = Tweet.find(1)


   end
 end




/app/views/tweets/status.html.erb
   <h1><%= @ tweet.status %></h1>

   <p>Posted by <%= @ tweet.zombie.name %></p>
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc
Rails for zombies slides cc

Más contenido relacionado

Destacado

อุปกรณ์คอมพิวเตอร์
อุปกรณ์คอมพิวเตอร์อุปกรณ์คอมพิวเตอร์
อุปกรณ์คอมพิวเตอร์natthaphorn_thepyoo
 
20111028 講演スライド
20111028 講演スライド20111028 講演スライド
20111028 講演スライドToru Watanabe
 
อุปกรณ์คอมพิวเตอร์
อุปกรณ์คอมพิวเตอร์อุปกรณ์คอมพิวเตอร์
อุปกรณ์คอมพิวเตอร์natthaphorn_thepyoo
 
ประวัติส่วนตัวของนักเรียนรายวิชาเพิ่มเติมคอมพิวเตอร์
ประวัติส่วนตัวของนักเรียนรายวิชาเพิ่มเติมคอมพิวเตอร์ประวัติส่วนตัวของนักเรียนรายวิชาเพิ่มเติมคอมพิวเตอร์
ประวัติส่วนตัวของนักเรียนรายวิชาเพิ่มเติมคอมพิวเตอร์natthaphorn_thepyoo
 
E learning di sekolah-sekolah
E learning di sekolah-sekolahE learning di sekolah-sekolah
E learning di sekolah-sekolahMrsEden
 
Problems Collection of Differential Equation II
Problems Collection of Differential Equation IIProblems Collection of Differential Equation II
Problems Collection of Differential Equation IIMeiva Lestari
 
Kotter change 8 step
Kotter change 8 stepKotter change 8 step
Kotter change 8 stepydelph
 

Destacado (15)

October 2015 e madhuram optimized
October 2015 e madhuram optimizedOctober 2015 e madhuram optimized
October 2015 e madhuram optimized
 
July 2015 emadhuram optimized
July 2015 emadhuram optimizedJuly 2015 emadhuram optimized
July 2015 emadhuram optimized
 
June 2015 e madhuram optimized
June 2015 e madhuram optimizedJune 2015 e madhuram optimized
June 2015 e madhuram optimized
 
trial ppt
trial ppttrial ppt
trial ppt
 
อุปกรณ์คอมพิวเตอร์
อุปกรณ์คอมพิวเตอร์อุปกรณ์คอมพิวเตอร์
อุปกรณ์คอมพิวเตอร์
 
20111028 講演スライド
20111028 講演スライド20111028 講演スライド
20111028 講演スライド
 
อุปกรณ์คอมพิวเตอร์
อุปกรณ์คอมพิวเตอร์อุปกรณ์คอมพิวเตอร์
อุปกรณ์คอมพิวเตอร์
 
ประวัติส่วนตัวของนักเรียนรายวิชาเพิ่มเติมคอมพิวเตอร์
ประวัติส่วนตัวของนักเรียนรายวิชาเพิ่มเติมคอมพิวเตอร์ประวัติส่วนตัวของนักเรียนรายวิชาเพิ่มเติมคอมพิวเตอร์
ประวัติส่วนตัวของนักเรียนรายวิชาเพิ่มเติมคอมพิวเตอร์
 
Onappathippu 2015 optimized
Onappathippu 2015 optimizedOnappathippu 2015 optimized
Onappathippu 2015 optimized
 
December kavithakal
December kavithakalDecember kavithakal
December kavithakal
 
E learning di sekolah-sekolah
E learning di sekolah-sekolahE learning di sekolah-sekolah
E learning di sekolah-sekolah
 
E madhuram may 2015
E madhuram may 2015E madhuram may 2015
E madhuram may 2015
 
Problems Collection of Differential Equation II
Problems Collection of Differential Equation IIProblems Collection of Differential Equation II
Problems Collection of Differential Equation II
 
Materiales plásticos
Materiales plásticosMateriales plásticos
Materiales plásticos
 
Kotter change 8 step
Kotter change 8 stepKotter change 8 step
Kotter change 8 step
 

Último

Anandtara Iris Residences Mundhwa Pune Brochure.pdf
Anandtara Iris Residences Mundhwa Pune Brochure.pdfAnandtara Iris Residences Mundhwa Pune Brochure.pdf
Anandtara Iris Residences Mundhwa Pune Brochure.pdfabbu831446
 
Provident Solitaire Park Square Kanakapura Road, Bangalore E- Brochure.pdf
Provident Solitaire Park Square Kanakapura Road, Bangalore E- Brochure.pdfProvident Solitaire Park Square Kanakapura Road, Bangalore E- Brochure.pdf
Provident Solitaire Park Square Kanakapura Road, Bangalore E- Brochure.pdffaheemali990101
 
The Role of Mortgage Brokers in Retirement Housing: Key Considerations
The Role of Mortgage Brokers in Retirement Housing: Key ConsiderationsThe Role of Mortgage Brokers in Retirement Housing: Key Considerations
The Role of Mortgage Brokers in Retirement Housing: Key Considerationssunlite Mortgage
 
Brigade Neopolis Kokapet, Hyderabad E- Brochure
Brigade Neopolis Kokapet, Hyderabad E- BrochureBrigade Neopolis Kokapet, Hyderabad E- Brochure
Brigade Neopolis Kokapet, Hyderabad E- Brochurefaheemali990101
 
Dynamic Netsoft A leader In Property management Software
Dynamic Netsoft A leader In Property management SoftwareDynamic Netsoft A leader In Property management Software
Dynamic Netsoft A leader In Property management SoftwareDynamic Netsoft
 
Covid 19 and Market Impact during the Pandemic
Covid 19 and Market Impact during the PandemicCovid 19 and Market Impact during the Pandemic
Covid 19 and Market Impact during the PandemicTim Wilmath
 
LCAR Unit 22 - Leasing and Property Management - 14th Edition Revised.pptx
LCAR Unit 22 - Leasing and Property Management - 14th Edition Revised.pptxLCAR Unit 22 - Leasing and Property Management - 14th Edition Revised.pptx
LCAR Unit 22 - Leasing and Property Management - 14th Edition Revised.pptxTom Blefko
 
A Brief History of Intangibles in Ad Valorem Taxation.pdf
A Brief History of Intangibles in Ad Valorem Taxation.pdfA Brief History of Intangibles in Ad Valorem Taxation.pdf
A Brief History of Intangibles in Ad Valorem Taxation.pdfTim Wilmath
 
83770-87607 ۞Call Girls In Near The Park Hotel (Cp) Delhi
83770-87607 ۞Call Girls In Near The Park Hotel (Cp) Delhi83770-87607 ۞Call Girls In Near The Park Hotel (Cp) Delhi
83770-87607 ۞Call Girls In Near The Park Hotel (Cp) Delhidollysharma2066
 
Call Girls In Sahibabad Ghaziabad ❤️8860477959 Low Rate Escorts Service In 24...
Call Girls In Sahibabad Ghaziabad ❤️8860477959 Low Rate Escorts Service In 24...Call Girls In Sahibabad Ghaziabad ❤️8860477959 Low Rate Escorts Service In 24...
Call Girls In Sahibabad Ghaziabad ❤️8860477959 Low Rate Escorts Service In 24...lizamodels9
 
Eco-Efficient Living: Redefining Sustainability through Leech's Green Design ...
Eco-Efficient Living: Redefining Sustainability through Leech's Green Design ...Eco-Efficient Living: Redefining Sustainability through Leech's Green Design ...
Eco-Efficient Living: Redefining Sustainability through Leech's Green Design ...Newman George Leech
 
MADHUGIRI FARM LAND BROCHURES (11)_compressed (1).pdf
MADHUGIRI FARM LAND BROCHURES (11)_compressed (1).pdfMADHUGIRI FARM LAND BROCHURES (11)_compressed (1).pdf
MADHUGIRI FARM LAND BROCHURES (11)_compressed (1).pdfknoxdigital1
 
Choose Noida's Leading Architect
Choose    Noida's    Leading   ArchitectChoose    Noida's    Leading   Architect
Choose Noida's Leading ArchitectMM Design Studio
 
Call Girls In Peeragarhi, Delhi↫8447779280↬Call Girls in Peeragarhi Delhi NCR
Call Girls In Peeragarhi, Delhi↫8447779280↬Call Girls in Peeragarhi Delhi NCRCall Girls In Peeragarhi, Delhi↫8447779280↬Call Girls in Peeragarhi Delhi NCR
Call Girls In Peeragarhi, Delhi↫8447779280↬Call Girls in Peeragarhi Delhi NCRasmaqueen5
 
The Importance of Parks and Recreation Areas in Reliaable Developers Plot Dev...
The Importance of Parks and Recreation Areas in Reliaable Developers Plot Dev...The Importance of Parks and Recreation Areas in Reliaable Developers Plot Dev...
The Importance of Parks and Recreation Areas in Reliaable Developers Plot Dev...Reliaable Developers
 
Kumar Fireworks Hadapsar Link Road Pune Brochure.pdf
Kumar Fireworks Hadapsar Link Road Pune Brochure.pdfKumar Fireworks Hadapsar Link Road Pune Brochure.pdf
Kumar Fireworks Hadapsar Link Road Pune Brochure.pdfBabyrudram
 
Managed Farmland Brochures to get more in
Managed Farmland Brochures to get more inManaged Farmland Brochures to get more in
Managed Farmland Brochures to get more inknoxdigital1
 

Último (20)

Anandtara Iris Residences Mundhwa Pune Brochure.pdf
Anandtara Iris Residences Mundhwa Pune Brochure.pdfAnandtara Iris Residences Mundhwa Pune Brochure.pdf
Anandtara Iris Residences Mundhwa Pune Brochure.pdf
 
Provident Solitaire Park Square Kanakapura Road, Bangalore E- Brochure.pdf
Provident Solitaire Park Square Kanakapura Road, Bangalore E- Brochure.pdfProvident Solitaire Park Square Kanakapura Road, Bangalore E- Brochure.pdf
Provident Solitaire Park Square Kanakapura Road, Bangalore E- Brochure.pdf
 
The Role of Mortgage Brokers in Retirement Housing: Key Considerations
The Role of Mortgage Brokers in Retirement Housing: Key ConsiderationsThe Role of Mortgage Brokers in Retirement Housing: Key Considerations
The Role of Mortgage Brokers in Retirement Housing: Key Considerations
 
Call Girls in Mahavir Nagar whatsaap call US +919953056974
Call Girls in Mahavir Nagar  whatsaap call US  +919953056974Call Girls in Mahavir Nagar  whatsaap call US  +919953056974
Call Girls in Mahavir Nagar whatsaap call US +919953056974
 
Brigade Neopolis Kokapet, Hyderabad E- Brochure
Brigade Neopolis Kokapet, Hyderabad E- BrochureBrigade Neopolis Kokapet, Hyderabad E- Brochure
Brigade Neopolis Kokapet, Hyderabad E- Brochure
 
Dynamic Netsoft A leader In Property management Software
Dynamic Netsoft A leader In Property management SoftwareDynamic Netsoft A leader In Property management Software
Dynamic Netsoft A leader In Property management Software
 
Covid 19 and Market Impact during the Pandemic
Covid 19 and Market Impact during the PandemicCovid 19 and Market Impact during the Pandemic
Covid 19 and Market Impact during the Pandemic
 
LCAR Unit 22 - Leasing and Property Management - 14th Edition Revised.pptx
LCAR Unit 22 - Leasing and Property Management - 14th Edition Revised.pptxLCAR Unit 22 - Leasing and Property Management - 14th Edition Revised.pptx
LCAR Unit 22 - Leasing and Property Management - 14th Edition Revised.pptx
 
A Brief History of Intangibles in Ad Valorem Taxation.pdf
A Brief History of Intangibles in Ad Valorem Taxation.pdfA Brief History of Intangibles in Ad Valorem Taxation.pdf
A Brief History of Intangibles in Ad Valorem Taxation.pdf
 
83770-87607 ۞Call Girls In Near The Park Hotel (Cp) Delhi
83770-87607 ۞Call Girls In Near The Park Hotel (Cp) Delhi83770-87607 ۞Call Girls In Near The Park Hotel (Cp) Delhi
83770-87607 ۞Call Girls In Near The Park Hotel (Cp) Delhi
 
Call Girls In Sahibabad Ghaziabad ❤️8860477959 Low Rate Escorts Service In 24...
Call Girls In Sahibabad Ghaziabad ❤️8860477959 Low Rate Escorts Service In 24...Call Girls In Sahibabad Ghaziabad ❤️8860477959 Low Rate Escorts Service In 24...
Call Girls In Sahibabad Ghaziabad ❤️8860477959 Low Rate Escorts Service In 24...
 
Eco-Efficient Living: Redefining Sustainability through Leech's Green Design ...
Eco-Efficient Living: Redefining Sustainability through Leech's Green Design ...Eco-Efficient Living: Redefining Sustainability through Leech's Green Design ...
Eco-Efficient Living: Redefining Sustainability through Leech's Green Design ...
 
MADHUGIRI FARM LAND BROCHURES (11)_compressed (1).pdf
MADHUGIRI FARM LAND BROCHURES (11)_compressed (1).pdfMADHUGIRI FARM LAND BROCHURES (11)_compressed (1).pdf
MADHUGIRI FARM LAND BROCHURES (11)_compressed (1).pdf
 
Choose Noida's Leading Architect
Choose    Noida's    Leading   ArchitectChoose    Noida's    Leading   Architect
Choose Noida's Leading Architect
 
Call Girls In Peeragarhi, Delhi↫8447779280↬Call Girls in Peeragarhi Delhi NCR
Call Girls In Peeragarhi, Delhi↫8447779280↬Call Girls in Peeragarhi Delhi NCRCall Girls In Peeragarhi, Delhi↫8447779280↬Call Girls in Peeragarhi Delhi NCR
Call Girls In Peeragarhi, Delhi↫8447779280↬Call Girls in Peeragarhi Delhi NCR
 
Low Rate Call Girls in Triveni Complex Delhi Call 9873940964
Low Rate Call Girls in Triveni Complex Delhi Call 9873940964Low Rate Call Girls in Triveni Complex Delhi Call 9873940964
Low Rate Call Girls in Triveni Complex Delhi Call 9873940964
 
The Importance of Parks and Recreation Areas in Reliaable Developers Plot Dev...
The Importance of Parks and Recreation Areas in Reliaable Developers Plot Dev...The Importance of Parks and Recreation Areas in Reliaable Developers Plot Dev...
The Importance of Parks and Recreation Areas in Reliaable Developers Plot Dev...
 
Kumar Fireworks Hadapsar Link Road Pune Brochure.pdf
Kumar Fireworks Hadapsar Link Road Pune Brochure.pdfKumar Fireworks Hadapsar Link Road Pune Brochure.pdf
Kumar Fireworks Hadapsar Link Road Pune Brochure.pdf
 
Managed Farmland Brochures to get more in
Managed Farmland Brochures to get more inManaged Farmland Brochures to get more in
Managed Farmland Brochures to get more in
 
young call girls in Lajpat Nagar,🔝 9953056974 🔝 escort Service
young call girls in Lajpat Nagar,🔝 9953056974 🔝 escort Serviceyoung call girls in Lajpat Nagar,🔝 9953056974 🔝 escort Service
young call girls in Lajpat Nagar,🔝 9953056974 🔝 escort Service
 

Rails for zombies slides cc

  • 1. This content is available free on created by http://RailsForZombies.org
  • 2. Feel free to delete this slide This means you can use the If you need to charge some content: money * You can modify / remix it to run an event which uses this content it can not be profitable. i.e. You should only be charging enough However: to cover costs. * You can’t charge money for it If profit is involved, Envy Labs * You must keep the attribution deserves a small cut, probably don’t you think? Maybe even consider having Envy Labs teach it in person perhaps? Email => Gregg@EnvyLabs.com This content is available free on created by http://RailsForZombies.org
  • 3. Recommendations for running •You’ll need 3-4 for Zombies through the a Live Rails hours to get tutorial, with enough time for labs Tutorial •Present these slides, then give students 20-30 minutes do do the exercises on RailsForZombies.org •Have students go through TryRuby.org ahead of time, if they’re not familiar with Ruby •If you’re not comfortable with presenting this material feel free to just play the videos on the website and Feel free to delete this slid not use these slides available free on created by This content is http://RailsForZombies.org
  • 4. Recommendations for creating •Make each episode a separate video, not one long one. a •If possible, don’t use slides video with these your laptop microphone, use a USB Microphone like: http://amzn.to/eHTMSJ •Seeing your face is more entertaining then just watching code. Please insert yourself into the content. •Keynote allows you to “Record Slideshow”, which is good for pacing the timing of the slides (not audio though). You can then export video with that timing. You’d then take this into another video editor. (this is how you to delete this slid Feel free export with animations) content is available free on This created by If you need an editor suggestion: Screenflow http://RailsForZombies.org
  • 5. An Introduction to Rails Episode #1 This content is available free on created by http://RailsForZombies.org
  • 7. Episode #1 Deep in the
  • 8.
  • 9. FOR ZO F MB IES!! !
  • 10. CRU D
  • 11. CRU D tweets
  • 12. CRU D tweets Rows { (we have 4)
  • 13. CRU Columns D Rows { (we have 4) { tweets (we have 3)
  • 14. CRU D
  • 15. CRU D id
  • 16. CRU D id status
  • 17. CRU D id status zombie
  • 18. CRU D id status zombie Zombie Challenge #1 Retrieve a hash of the tweet with id = 3
  • 19. CRU D id status zombie Zombie Challenge #1 Retrieve a hash of the tweet with id = 3 Result b = { :status => "I just ate some delicious brains", :zombie => "Jim" }
  • 20. CRU Hash D Series of key value pairs b = { :status => "I just ate some delicious brains", :zombie => "Jim" }
  • 21. CRU Hash D Series of key value pairs b = { :status => "I just ate some delicious brains", :zombie => "Jim" } puts b[:status]
  • 22. CRU Hash D Series of key value pairs b = { :status => "I just ate some delicious brains", :zombie => "Jim" } puts b[:status] "I just ate some delicious brains"
  • 23. CRU Hash D Series of key value pairs b = { :status => "I just ate some delicious brains", :zombie => "Jim" } puts b[:status] "I just ate some delicious brains" puts b[:zombie]
  • 24. CRU Hash D Series of key value pairs b = { :status => "I just ate some delicious brains", :zombie => "Jim" } puts b[:status] "I just ate some delicious brains" puts b[:zombie] "Jim"
  • 25. CRU Hash D Series of key value pairs b = { :status => "I just ate some delicious brains", :zombie => "Jim" } puts b[:status] "I just ate some delicious brains" puts b[:zombie] "Jim" puts b[:zombie] + " said " + b[:status]
  • 26. CRU Hash D Series of key value pairs b = { :status => "I just ate some delicious brains", :zombie => "Jim" } puts b[:status] "I just ate some delicious brains" puts b[:zombie] "Jim" puts b[:zombie] + " said " + b[:status] "Jim said I just ate some delicious brains"
  • 27. CRU Hash D Series of key value pairs b = { :status => "I just ate some delicious brains", :zombie => "Jim" } puts b[:status] "I just ate some delicious brains" puts b[:zombie] "Jim" puts b[:zombie] + " said " + b[:status] "Jim said I just ate some delicious brains"
  • 28. CRU D
  • 29. CRU tweets D id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 30. CRU tweets D id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash ombie Challenge #1 Retrieve a hash of the tweet with id = 3
  • 31. CRU tweets D id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash ombie Challenge #1 Retrieve a hash of the tweet with id = 3 Answer t = Tweet.find(3)
  • 32. CRU tweets D id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash ombie Challenge #1 Retrieve a hash of the tweet with id = 3 Answer t = Tweet.find(3) puts t[:id]
  • 33. CRU tweets D id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash ombie Challenge #1 Retrieve a hash of the tweet with id = 3 Answer t = Tweet.find(3) puts t[:id] 3
  • 34. CRU tweets D id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash ombie Challenge #1 Retrieve a hash of the tweet with id = 3 Answer t = Tweet.find(3) puts t[:id] 3 puts t[:status]
  • 35. CRU tweets D id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash ombie Challenge #1 Retrieve a hash of the tweet with id = 3 Answer t = Tweet.find(3) puts t[:id] 3 puts t[:status] "I just ate some delicious brains."
  • 36. CRU tweets D id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash ombie Challenge #1 Retrieve a hash of the tweet with id = 3 Answer t = Tweet.find(3) puts t[:id] 3 puts t[:status] "I just ate some delicious brains." puts t[:zombie]
  • 37. CRU tweets D id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash ombie Challenge #1 Retrieve a hash of the tweet with id = 3 Answer t = Tweet.find(3) puts t[:id] 3 puts t[:status] "I just ate some delicious brains." puts t[:zombie] "Jim"
  • 38. CRU t = Tweet.find(3) D puts t[:id] puts t[:status] puts t[:zombie]
  • 39. CRU t = Tweet.find(3) D puts t[:id] puts t.id Sam puts t[:status] eA puts t[:zombie] s
  • 40. CRU t = Tweet.find(3) D puts t[:id] puts t.id Sam puts t[:status] puts t.status eA puts t[:zombie] s
  • 41. CRU t = Tweet.find(3) D puts t[:id] puts t.id Sam puts t[:status] puts t.status eA puts t[:zombie] puts t.zombie s
  • 42. CRU t = Tweet.find(3) D puts t[:id] puts t.id Sam puts t[:status] puts t.status eA puts t[:zombie] puts t.zombie s Answer puts t.id 3 puts t.status "I just ate some delicious brains." puts t.zombie "Jim"
  • 44. CRU t = Tweet.find(3) D tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 45. CRU t = Tweet.find(3) D Pluralize tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 49. t = Tweet.new Create t.status = "I <3 brains." t.save Read Update Delete
  • 50. t = Tweet.new Create t.status = "I <3 brains." t.save Read Tweet.find(3) Update Delete
  • 51. t = Tweet.new Create t.status = "I <3 brains." t.save Read Tweet.find(3) t = Tweet.find(3) Update t.zombie = "EyeballChomper" t.save Delete
  • 52. t = Tweet.new Create t.status = "I <3 brains." t.save Read Tweet.find(3) t = Tweet.find(3) Update t.zombie = "EyeballChomper" t.save t = Tweet.find(3) Delete t.destroy
  • 53. Create Syntax t = Tweet.new t.status = "I <3 brains." t.zombie = "Jim" t.save
  • 54. Create Syntax the id . t = Tweet.new n’t set a lly e do anu t.status = "I <3 brains." tic e w s set m t.zombie = "Jim" No et t.save he id g or us. T f
  • 55. Create Syntax the id . t = Tweet.new n’t set a lly e do anu t.status = "I <3 brains." tic e w s set m t.zombie = "Jim" No et t.save he id g or us. T f Alternate Syntax
  • 56. Create Syntax the id . t = Tweet.new n’t set a lly e do anu t.status = "I <3 brains." tic e w s set m t.zombie = "Jim" No et t.save he id g or us. T f Alternate Syntax t = Tweet.new(:status => "I <3 brains", :zombie => "Jim") t.save
  • 57. Create Syntax the id . t = Tweet.new n’t set a lly e do anu t.status = "I <3 brains." tic e w s set m t.zombie = "Jim" No et t.save he id g or us. T f Alternate Syntax t = Tweet.new(:status => "I <3 brains", :zombie => "Jim") t.save Tweet.create(:status => "I <3 brains", :zombie => "Jim")
  • 58. Read Syntax
  • 59. Read Syntax Tweet.find(2) # Returns a single item
  • 60. Read Syntax Tweet.find(2) # Returns a single item Tweet.find(3, 4, 5) # Returns an array
  • 61. Read Syntax Tweet.find(2) # Returns a single item Tweet.find(3, 4, 5) # Returns an array Tweet.first # Returns the first tweet
  • 62. Read Syntax Tweet.find(2) # Returns a single item Tweet.find(3, 4, 5) # Returns an array Tweet.first # Returns the first tweet Tweet.last # Returns the last tweet
  • 63. Read Syntax Tweet.find(2) # Returns a single item Tweet.find(3, 4, 5) # Returns an array Tweet.first # Returns the first tweet Tweet.last # Returns the last tweet Tweet.all # Returns all the tweets
  • 64. Read Syntax Tweet.find(2) # Returns a single item Tweet.find(3, 4, 5) # Returns an array Tweet.first # Returns the first tweet Tweet.last # Returns the last tweet Tweet.all # Returns all the tweets Tweet.count # Returns number of tweets
  • 65. Read Syntax Tweet.find(2) # Returns a single item Tweet.find(3, 4, 5) # Returns an array Tweet.first # Returns the first tweet Tweet.last # Returns the last tweet Tweet.all # Returns all the tweets Tweet.count # Returns number of tweets Tweet.order(:zombie) # All ordered by zombie
  • 66. Read Syntax Tweet.find(2) # Returns a single item Tweet.find(3, 4, 5) # Returns an array Tweet.first # Returns the first tweet Tweet.last # Returns the last tweet Tweet.all # Returns all the tweets Tweet.count # Returns number of tweets Tweet.order(:zombie) # All ordered by zombie Tweet.limit(10) # Only 10 tweets
  • 67. Read Syntax Tweet.find(2) # Returns a single item Tweet.find(3, 4, 5) # Returns an array Tweet.first # Returns the first tweet Tweet.last # Returns the last tweet Tweet.all # Returns all the tweets Tweet.count # Returns number of tweets Tweet.order(:zombie) # All ordered by zombie Tweet.limit(10) # Only 10 tweets Tweet.where(:zombie => "ash") # Only tweets by Ash
  • 68. Read Syntax Tweet.find(2) # Returns a single item Tweet.find(3, 4, 5) # Returns an array Tweet.first # Returns the first tweet Tweet.last # Returns the last tweet Tweet.all # Returns all the tweets Tweet.count # Returns number of tweets Tweet.order(:zombie) # All ordered by zombie Tweet.limit(10) # Only 10 tweets Tweet.where(:zombie => "ash") # Only tweets by Ash Tweet.where(:zombie => "ash").order(:zombie).limit(10) method chaining
  • 69. Update Syntax t = Tweet.find(3) t.zombie = "EyeballChomper" t.save
  • 70. Update Syntax t = Tweet.find(3) t.zombie = "EyeballChomper" t.save t = Tweet.find(2) t.attributes = { :status => "Can I munch your eyeballs?", :zombie => "EyeballChomper" } t.save
  • 71. Update Syntax t = Tweet.find(3) t.zombie = "EyeballChomper" t.save t = Tweet.find(2) t.attributes = { :status => "Can I munch your eyeballs?", :zombie => "EyeballChomper" } t.save t = Tweet.find(2) t.update_attributes( :status => "Can I munch your eyeballs?", :zombie => "EyeballChomper" )
  • 72. Delete Syntax t = Tweet.find(2) t.destroy
  • 73. Delete Syntax t = Tweet.find(2) t.destroy Tweet.find(2).destroy
  • 74. Delete Syntax t = Tweet.find(2) t.destroy Tweet.find(2).destroy Tweet.destroy_all
  • 75. Zombie http://railsforzombies.org Stop when you reach the video for Lab 2 Don’t worry about watching any of the videos Download the slides so you can remember the syntax
  • 76. An Introduction to Rails Episode #2 This content is available free on created by http://RailsForZombies.org
  • 77. Chapter 2 Models taste like chicken
  • 80. Model t = Tweet.find(3) Tweet s tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 81. Model t = Tweet.find(3) Tweet s ? tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 82. Model t = Tweet.find(3) Tweet s app/models/tweet.rb class Tweet < ActiveRecord::Base end tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 83. Model Tweet s app/models/tweet.rb class Tweet < ActiveRecord::Base end tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 84. Model Tweet s app/models/tweet.rb class Tweet < ActiveRecord::Base end tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 85. Model Tweet s app/models/tweet.rb class Tweet < ActiveRecord::Base end Maps the class to the tweets table id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 86. Model Tweet s app/models/tweet.rb class Tweet < ActiveRecord::Base end Maps the class to the tweets table id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 87. Model app/models/tweet.rb class Tweet < ActiveRecord::Base s end tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 88. Model app/models/tweet.rb class Tweet < ActiveRecord::Base s end t = Tweet.find(3) tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 89. Model app/models/tweet.rb class Tweet < ActiveRecord::Base s end t = Tweet.find(3) class tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 90. Model app/models/tweet.rb class Tweet < ActiveRecord::Base s end t = Tweet.find(3) class tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 91. Model app/models/tweet.rb class Tweet < ActiveRecord::Base s end instance of Tweet t = Tweet.find(3) Tweet #3 class tweets id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 92. Validations? id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 93. Validations? id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash t = Tweet.new t.save
  • 94. Validations? id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash 5 t = Tweet.new t.save
  • 95. Valida tio app/models/tweet.rb ns class Tweet < ActiveRecord::Base end
  • 96. Valida tio app/models/tweet.rb ns class Tweet < ActiveRecord::Base validates_presence_of :status end
  • 97. Valida tio app/models/tweet.rb ns class Tweet < ActiveRecord::Base validates_presence_of :status end > t = Tweet.new => #<Tweet id: nil, status: nil, zombie: nil>
  • 98. Valida tio app/models/tweet.rb ns class Tweet < ActiveRecord::Base validates_presence_of :status end > t = Tweet.new => #<Tweet id: nil, status: nil, zombie: nil> > t.save => false
  • 99. Valida tio app/models/tweet.rb ns class Tweet < ActiveRecord::Base validates_presence_of :status end > t = Tweet.new => #<Tweet id: nil, status: nil, zombie: nil> > t.save => false > t.errors => {:status=>["can't be blank"]}
  • 100. Valida tio app/models/tweet.rb ns class Tweet < ActiveRecord::Base validates_presence_of :status end > t = Tweet.new => #<Tweet id: nil, status: nil, zombie: nil> > t.save => false > t.errors => {:status=>["can't be blank"]} > t.errors[:status] => "can't be blank"
  • 101. Valida tio ns
  • 102. Valida tio validates_presence_of :status ns validates_numericality_of :fingers validates_uniqueness_of :toothmarks validates_confirmation_of :password validates_acceptance_of :zombification validates_length_of :password, :minimum => 3 validates_format_of :email, :with => /regex/i validates_inclusion_of :age, :in => 21..99 validates_exclusion_of :age, :in => 0...21, :message => “Sorry you must be over 21”
  • 103. Valida tio ns
  • 104. te alidation Valida Attribu V tio validates :status, :presence => true ns
  • 105. te alidation Valida Attribu V tio validates :status, :presence => true ns validates :status, :length => { :minimum => 3 }
  • 106. te alidation Valida Attribu V tio validates :status, :presence => true ns validates :status, :length => { :minimum => 3 } validates :status, :presence => true, :length => { :minimum => 3 }
  • 107. te alidation Valida Attribu V tio validates :status, :presence => true ns validates :status, :length => { :minimum => 3 } validates :status, :presence => true, :length => { :minimum => 3 } :presence => true :uniqueness => true :numericality => true :length => { :minimum => 0, :maximum => 2000 } :format => { :with => /.*/ } :inclusion => { :in => [1,2,3] } :exclusion => { :in => [1,2,3] } :acceptance => true :confirmation => true
  • 108. el a ti o nship s Because they always travel in packs
  • 109. Relatio tweets nship id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 110. Relatio tweets nship id status zombie 1 Where can I get a good bite to eat? Ash 2 My left arm is missing, but I don't care. Bob 3 I just ate some delicious brains. Jim 4 OMG, my fingers turned green. #FML Ash
  • 111. Relatio tweets nship id status 1 Where can I get a good bite to eat? 2 My left arm is missing, but I don't care. 3 I just ate some delicious brains. 4 OMG, my fingers turned green. #FML
  • 112. Relatio tweets nship id status 1 Where can I get a good bite to eat? 2 My left arm is missing, but I don't care. 3 I just ate some delicious brains. 4 OMG, my fingers turned green. #FML zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 113. Relatio tweets nship id status 1 Where can I get a good bite to eat? 2 My left arm is missing, but I don't care. 3 I just ate some delicious brains. 4 OMG, my fingers turned green. #FML zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 114. Relatio tweets nship id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 115. Relatio tweets nship id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 116. Relatio tweets nship id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 5 Your eyelids taste like bacon. 2 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 117. Relatio tweets nship id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 5 Your eyelids taste like bacon. 2 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 118. Relatio tweets nship id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 5 Your eyelids taste like bacon. 2 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 119. tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 120. A Tweet tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 121. A Tweet belongs to tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 122. A Tweet belongs to a Zombie tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 123. A Tweet belongs to a Zombie app/models/tweet.rb class Tweet < ActiveRecord::Base end tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 124. A Tweet belongs to a Zombie app/models/tweet.rb class Tweet < ActiveRecord::Base belongs_to :zombie end Singular tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 125. A Tweet belongs to a Zombie A Zombie app/models/tweet.rb class Tweet < ActiveRecord::Base belongs_to :zombie end Singular tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 126. A Tweet belongs to a Zombie A Zombie has many app/models/tweet.rb class Tweet < ActiveRecord::Base belongs_to :zombie end Singular tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 127. A Tweet belongs to a Zombie A Zombie has many Tweets app/models/tweet.rb class Tweet < ActiveRecord::Base belongs_to :zombie end Singular tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 128. A Tweet belongs to a Zombie A Zombie has many Tweets app/models/tweet.rb app/models/zombie.rb class Tweet < ActiveRecord::Base class Zombie < ActiveRecord::Base belongs_to :zombie end end Singular tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 129. A Tweet belongs to a Zombie A Zombie has many Tweets app/models/tweet.rb app/models/zombie.rb class Tweet < ActiveRecord::Base class Zombie < ActiveRecord::Base belongs_to :zombie has_many :tweets end end Plural Singular tweets id status zombie_id 1 Where can I get a good bite to eat? 1 2 My left arm is missing, but I don't care. 2 3 I just ate some delicious brains. 3 4 OMG, my fingers turned green. #FML 1 zombies id name graveyard 1 Ash Glen Haven Memorial Cemetery 2 Bob Chapel Hill Cemetery 3 Jim My Father’s Basement
  • 130. Relatio nship A Tweet belongs to a Zombie
  • 131. Relatio nship A Tweet belongs to a Zombie > z = Zombie.find(2) => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">
  • 132. Relatio nship A Tweet belongs to a Zombie > z = Zombie.find(2) => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z) => #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2>
  • 133. Relatio nship A Tweet belongs to a Zombie > z = Zombie.find(2) => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z) => #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2> > t.zombie => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery">
  • 134. Relatio nship A Tweet belongs to a Zombie > z = Zombie.find(2) => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z) => #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2> > t.zombie => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t.zombie.name => "Bob"
  • 135. Relatio nship A Tweet belongs to a Zombie > z = Zombie.find(2) => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z) => #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2> > t.zombie => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t.zombie.name => "Bob" > ash = Zombie.find(1) => #<Zombie id: 1, name: "Ash", graveyard: "Glen Haven Cemetery">
  • 136. Relatio nship A Tweet belongs to a Zombie > z = Zombie.find(2) => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z) => #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2> > t.zombie => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t.zombie.name => "Bob" > ash = Zombie.find(1) => #<Zombie id: 1, name: "Ash", graveyard: "Glen Haven Cemetery"> > ash.tweets.count => 4
  • 137. Relatio nship A Tweet belongs to a Zombie > z = Zombie.find(2) => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t = Tweet.create(:status => "Your eyelids taste like bacon.", :zombie => z) => #<Tweet id: 5, status: "Your eyelids taste like bacon.", zombie_id: 2> > t.zombie => #<Zombie id: 2, name: "Bob", graveyard: "Chapel Hill Cemetery"> > t.zombie.name => "Bob" > ash = Zombie.find(1) => #<Zombie id: 1, name: "Ash", graveyard: "Glen Haven Cemetery"> > ash.tweets.count => 4 > ash.tweets => [#<Tweet id: 1, status: "Where can I get a good bite to eat?", zombie_id: 1>, #<Tweet id: 4, status: "OMG, my fingers turned green. #FML", zombie_id: 1>]
  • 138. Zombie
  • 139. An Introduction to Rails Episode # This content is available free on created by http://RailsForZombies.org
  • 140. Chapter 3 The View ain’t always pretty I’m so gonna eat his brains
  • 142. Vie Our Application Stack ws 4 Components
  • 143. Vie Our Application Stack ws Models 4 Components
  • 144. Vie Our Application Stack ws Views Models 4 Components
  • 145. Views
  • 147. Views zombie_twitter app views
  • 148. Views zombie_twitter app views zombies tweets
  • 149. Views zombie_twitter app views zombies tweets index.html.erb show.html.erb
  • 150. Views zombie_twitter app views zombies List all tweets tweets index.html.erb show.html.erb
  • 151. Views zombie_twitter app views zombies List all tweets tweets index.html.erb View a tweet show.html.erb
  • 152. Views Edible Rotting Bodies zombie_twitter app views zombies List all tweets tweets index.html.erb View a tweet show.html.erb
  • 153. Views Edible Rotting Bodies Embedded Ruby zombie_twitter Ruby inside HTML app views zombies List all tweets tweets index.html.erb View a tweet show.html.erb
  • 156. Show a tweet <% ... %> Evaluate Ruby
  • 157. Show a tweet <% ... %> Evaluate Ruby <%= ... %> Eval and print result
  • 158. Show a tweet <% ... %> Evaluate Ruby <%= ... %> Eval and print result /app/views/tweets/show.html.erb <!DOCTYPE html> <html> <head><title>Twitter for Zombies</title></head> <body> <img src="/images/twitter.png" /> </body></html>
  • 159. Show a tweet <% ... %> Evaluate Ruby <%= ... %> Eval and print result /app/views/tweets/show.html.erb <!DOCTYPE html> <html> <head><title>Twitter for Zombies</title></head> <body> <img src="/images/twitter.png" /> <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p> </body></html>
  • 160. Show a tweet <% ... %> Evaluate Ruby <%= ... %> Eval and print result /app/views/tweets/show.html.erb <!DOCTYPE html> <html> <head><title>Twitter for Zombies</title></head> <body> <img src="/images/twitter.png" /> FYI, This code <% tweet = Tweet.find(1) %> sucks a little.. <h1><%= tweet.status %></h1> (for 2 reasons) <p>Posted by <%= tweet.zombie.name %></p> </body></html>
  • 161. Show a tweet <% ... %> Evaluate Ruby <%= ... %> Eval and print result /app/views/tweets/show.html.erb <!DOCTYPE html> <html> <head><title>Twitter for Zombies</title></head> <body> <img src="/images/twitter.png" /> <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p> </body></html>
  • 162. Show a tweet /app/views/layouts/ application.html.erb <!DOCTYPE html> <html> <head><title>Twitter for Zombies</title></head> <body> <img src="/images/twitter.png" /> </body></html> /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 163. Show a tweet /app/views/layouts/ application.html.erb <!DOCTYPE html> <html> <head><title>Twitter for Zombies</title></head> <body> <img src="/images/twitter.png" /> <%= yield %> </body></html> /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 164. Views zombie_twitter app views zombies List all tweets tweets index.html.erb View a tweet show.html.erb
  • 165. Views zombie_twitter app views layouts zombies List all tweets tweets index.html.erb View a tweet show.html.erb
  • 166. Views zombie_twitter app views The main layout layouts application.html.erb zombies List all tweets tweets index.html.erb View a tweet show.html.erb
  • 167. Additional Layout Components /app/views/layouts/ application.html.erb <!DOCTYPE html> <html> <head> <title>Twitter for Zombies</title> </head> <body> <img src="/images/twitter.png" /> <%= yield %> </body></html>
  • 168. Additional Layout Components /app/views/layouts/ application.html.erb <!DOCTYPE html> <html> <head> <title>Twitter for Zombies</title> </head> <body> <img src="/images/twitter.png" /> <%= yield %> </body></html>
  • 169. Additional Layout Components /app/views/layouts/ application.html.erb <!DOCTYPE html> <html> <head> <title>Twitter for Zombies</title> <%= stylesheet_link_tag :all %> </head> <body> <img src="/images/twitter.png" /> <%= yield %> </body></html>
  • 170. Additional Layout Components /app/views/layouts/ application.html.erb <!DOCTYPE html> <html> <head> <title>Twitter for Zombies</title> <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> </head> <body> <img src="/images/twitter.png" /> <%= yield %> </body></html>
  • 171. Additional Layout Components /app/views/layouts/ application.html.erb <!DOCTYPE html> <html> <head> <title>Twitter for Zombies</title> <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %> </head> <body> <img src="/images/twitter.png" /> <%= yield %> </body></html>
  • 172. Additional Layout Components <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
  • 173. Additional Layout Components <%= stylesheet_link_tag :all %> Includ styles e all heets <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
  • 174. Additional Layout Components <%= stylesheet_link_tag :all %> Includ zombie_twitter styles e all public heets stylesheets <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
  • 175. Additional Layout Components <%= stylesheet_link_tag :all %> Includ zombie_twitter styles e all public heets stylesheets Renders <link href="/stylesheets/scaffold.css" media="screen" rel="stylesheet" type="text/css" /> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
  • 176. Additional Layout Components <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
  • 177. Additional Layout Components <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> Includ e d ef ault J S <%= csrf_meta_tag %>
  • 178. Additional Layout Components <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> Includ zombie_twitter e d ef ault J public S javascripts <%= csrf_meta_tag %>
  • 179. Additional Layout Components <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> Includ zombie_twitter e d ef ault J public S javascripts Renders <script Proto src="/javascripts/prototype.js" type="text/javascript"></script> <script type src="/javascripts/effects.js" type="text/javascript"></script> Javas <script Fram c r ip t src="/javascripts/dragdrop.js" type="text/javascript"></script> <script <script ework src="/javascripts/controls.js" type="text/javascript"></script> src="/javascripts/rails.js" type="text/javascript"></script> <script src="/javascripts/application.js" type="text/javascript"></script> <%= csrf_meta_tag %>
  • 180. Additional Layout Components <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %>
  • 181. Additional Layout Components <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %> Zombie Hacker <form Site target="http://yoursite.co m"> Think Your Site comm spam ent
  • 182. Additional Layout Components <%= stylesheet_link_tag :all %> <%= javascript_include_tag :defaults %> <%= csrf_meta_tag %> Zombie Hacker <form Site target="http://yoursite.co m"> Think Your Site comm Renders spam ent <meta name="csrf-param" content="authenticity_token"/> <meta name="csrf-token" content="I+d..jI="/> Automatically adds this to forms
  • 183. Root path and images
  • 184. Root path and images http://ZombieTwitter.com/[something]
  • 185. Root path and images http://ZombieTwitter.com/[something] zombie_twitter lic ub to public /p in e go xi sts rwis stylesheets I f e othe javascripts e it, Ra ils images us Example <img src="/images/twitter.png" />
  • 187. Adding a Link /app/views/tweets/show.html.erb ... <p>Posted by <%= tweet.zombie.name %></p>
  • 188. Adding a Link /app/views/tweets/show.html.erb bi ea ... ez om ak ink <p>Posted by <%= tweet.zombie.name %></p> M l
  • 189. Adding a Link /app/views/tweets/show.html.erb bi ea ... ez om ak ink <p>Posted by <%= tweet.zombie.name %></p> M l <%= %>
  • 190. Adding a Link /app/views/tweets/show.html.erb bi ea ... ez om ak ink <p>Posted by <%= tweet.zombie.name %></p> M l <%= link_to %>
  • 191. Adding a Link /app/views/tweets/show.html.erb bi ea ... ez om ak ink <p>Posted by <%= tweet.zombie.name %></p> M l <%= link_to tweet.zombie.name %> Link Text
  • 192. Adding a Link /app/views/tweets/show.html.erb bi ea ... ez om ak ink <p>Posted by <%= tweet.zombie.name %></p> M l <%= link_to tweet.zombie.name , zombie_path(tweet.zombie) %> Link Text Link Path (URL)
  • 193. Adding a Link /app/views/tweets/show.html.erb bi ea ... ez om ak ink <p>Posted by <%= tweet.zombie.name %></p> M l <%= link_to tweet.zombie.name , zombie_path(tweet.zombie) %> Link Text Link Path (URL) Renders <a href="/zombies/1">Ash</a>
  • 194. Adding a Link /app/views/tweets/show.html.erb bi ea ... ez om ak ink <p>Posted by <%= tweet.zombie.name %></p> M l <%= link_to tweet.zombie.name , zombie_path(tweet.zombie) %> Link Text Link Path (URL) Renders <a href="/zombies/1">Ash</a> We can also write as <%= link_to tweet.zombie.name, tweet.zombie %> Link Text Object to Show
  • 195.
  • 196. Method link_to with it? y ou use ons can W hat opti
  • 197. Method link_to with it? y ou use ons can W hat opti 1. Look in the source
  • 198. Method link_to with it? y ou use ons can W hat opti 1. Look in the source Command Line
  • 199. Method link_to with it? y ou use ons can W hat opti 1. Look in the source Command Line git clone http://github.com/rails/rails.git
  • 200. Method link_to with it? y ou use ons can W hat opti 1. Look in the source Command Line git clone http://github.com/rails/rails.git cd rails
  • 201. Method link_to with it? y ou use ons can W hat opti 1. Look in the source Command Line git clone http://github.com/rails/rails.git cd rails Open your editor and search for “def link_to”
  • 202. Method link_to with it? y ou use ions can W hat op t 2. Look at api.rubyonrails.org (and search for link_to)
  • 204. Method link_to with it? y ou use ions can W hat op t
  • 205. Method link_to with it? y ou use ions can W hat op t 3. API Dock (online Ruby and Rails docs) http://apidock.com/rails
  • 206.
  • 207. Method with it? link_to y ou use ions can W hat op t
  • 208. Method with it? link_to y ou use ions can W hat op t 4. Rails Searchable API Doc (local download or online) http://railsapi.com/
  • 210.
  • 211.
  • 212.
  • 213. <%= link_to @tweet.zombie.name, @tweet.zombie, :confirm => "Are you sure?" %>
  • 214. <%= link_to @tweet.zombie.name, @tweet.zombie, :confirm => "Are you sure?" %>
  • 215. Views zombie_twitter app views The main layout layouts application.html.erb zombies List all tweets tweets index.html.erb View a tweet show.html.erb
  • 218. Views List Tweets /app/views/tweets/index.html.erb
  • 219. Views List Tweets /app/views/tweets/index.html.erb <h1>Listing tweets</h1> <table> <tr> <th>Status</th> <th>Zombie</th> </tr>
  • 220. Views List Tweets /app/views/tweets/index.html.erb <h1>Listing tweets</h1> <table> <tr> <th>Status</th> <th>Zombie</th> </tr> <% Tweet.all.each do |tweet| %>
  • 221. Views List Tweets /app/views/tweets/index.html.erb <h1>Listing tweets</h1> <table> <tr> <th>Status</th> <th>Zombie</th> </tr> <% Tweet.all.each do |tweet| %> <tr> <td><%= <td><%= </tr> <% end %> </table>
  • 222. Views List Tweets /app/views/tweets/index.html.erb <h1>Listing tweets</h1> <table> <tr> <th>Status</th> <th>Zombie</th> </tr> <% Tweet.all.each do |tweet| %> <tr> <td><%= tweet.status %></td> <td><%= </tr> <% end %> </table>
  • 223. Views List Tweets /app/views/tweets/index.html.erb <h1>Listing tweets</h1> <table> <tr> <th>Status</th> <th>Zombie</th> </tr> <% Tweet.all.each do |tweet| %> <tr> <td><%= tweet.status %></td> <td><%= tweet.zombie.name %></td> </tr> <% end %> </table>
  • 224. Views List Tweets /app/views/tweets/index.html.erb <h1>Listing tweets</h1> <table> <tr> <th>Status</th> <th>Zombie</th> </tr> What they return <% Tweet.all.each do |tweet| %> Tweet class <tr> <td><%= tweet.status %></td> <td><%= tweet.zombie.name %></td> </tr> <% end %> </table>
  • 225. Views List Tweets /app/views/tweets/index.html.erb <h1>Listing tweets</h1> <table> <tr> <th>Status</th> <th>Zombie</th> </tr> What they return <% Tweet.all.each do |tweet| %> Tweet class <tr> <td><%= tweet.status %></td> <td><%= tweet.zombie.name %></td> Tweet.all array of tweets </tr> <% end %> </table>
  • 226. Views List Tweets /app/views/tweets/index.html.erb <h1>Listing tweets</h1> <table> <tr> <th>Status</th> <th>Zombie</th> </tr> What they return <% Tweet.all.each do |tweet| %> Tweet class <tr> <td><%= tweet.status %></td> <td><%= tweet.zombie.name %></td> Tweet.all array of tweets </tr> <% end %> tweet single tweet </table>
  • 227. Create Links Views /app/views/tweets/index.html.erb <% Tweet.all.each do |tweet| %> <tr> <td><%= tweet.status %></td> <td><%= tweet.zombie.name %></td> </tr> <% end %>
  • 228. Create Links Views /app/views/tweets/index.html.erb <% Tweet.all.each do |tweet| %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= tweet.zombie.name %></td> </tr> <% end %>
  • 229. Create Links Views /app/views/tweets/index.html.erb <% Tweet.all.each do |tweet| %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= link_to tweet.zombie.name, tweet.zombie %></td> </tr> <% end %>
  • 230. Empty Table?Views <% Tweet.all.each do |tweet| %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= link_to tweet.zombie.name, tweet.zombie %></td> </tr> <% end %>
  • 231. Empty Table?Views <% Tweet.all.each do |tweet| %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= link_to tweet.zombie.name, tweet.zombie %></td> </tr> <% end %>
  • 232. Empty Table?Views <% Tweet.all.each do |tweet| %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= link_to tweet.zombie.name, tweet.zombie %></td> </tr> <% end %>
  • 233. Empty Table?Views <% Tweet.all.each do |tweet| %> ... <% end %>
  • 234. Empty Table?Views <% tweets = Tweet.all %> <% .each do |tweet| %> ... <% end %>
  • 235. Empty Table?Views <% tweets = Tweet.all %> <% tweets.each do |tweet| %> ... <% end %>
  • 236. Empty Table?Views <% tweets = Tweet.all %> <% tweets.each do |tweet| %> ... <% end %> <% if tweets.size == 0 %> <em>No tweets found</em> <% end %>
  • 237. Empty Table?Views <% tweets = Tweet.all %> <% tweets.each do |tweet| %> ... <% end %> <% if tweets.empty? %> <em>No tweets found</em> <% end %>
  • 238. Empty Table?Views <% tweets = Tweet.all %> <% tweets.each do |tweet| %> ... <% end %> <% if tweets.empty? %> <em>No tweets found</em> <% end %>
  • 239. Edit & Delete Links?
  • 240. Edit & Delete Links?
  • 241. Edit & Delete Links? <% tweets.each do |tweet| %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= link_to tweet.zombie.name, tweet.zombie %></td> </tr> <% end %>
  • 242. Edit & Delete Links? <% tweets.each do |tweet| %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= link_to tweet.zombie.name, tweet.zombie %></td> <td><%= link_to "Edit", edit_tweet_path(tweet) %></td> </tr> <% end %>
  • 243. Edit & Delete Links? <% tweets.each do |tweet| %> <tr> <td><%= link_to tweet.status, tweet %></td> <td><%= link_to tweet.zombie.name, tweet.zombie %></td> <td><%= link_to "Edit", edit_tweet_path(tweet) %></td> <td><%= link_to "Delete", tweet, :method => :delete %></td> </tr> <% end %>
  • 244. All links for Tweets
  • 245. All links for Tweets <%= link_to "<link text>", <code> %>
  • 246. All links for Tweets <%= link_to "<link text>", <code> %> Action Code The URL Generated List all tweets tweets_path /tweets New tweet form new_tweet_path /tweets/new
  • 247. All links for Tweets <%= link_to "<link text>", <code> %> Action Code The URL Generated List all tweets tweets_path /tweets New tweet form new_tweet_path /tweets/new
  • 248. All links for Tweets <%= link_to "<link text>", <code> %> Action Code The URL Generated List all tweets tweets_path /tweets New tweet form new_tweet_path /tweets/new
  • 249. All links for Tweets <%= link_to "<link text>", <code> %> Action Code The URL Generated List all tweets tweets_path /tweets New tweet form new_tweet_path /tweets/new These paths n tweet = Tweet.find(1) eed a tweet
  • 250. All links for Tweets <%= link_to "<link text>", <code> %> Action Code The URL Generated List all tweets tweets_path /tweets New tweet form new_tweet_path /tweets/new These paths n tweet = Tweet.find(1) eed a tweet Action Code The URL Generated Show a tweet tweet /tweets/1 Edit a tweet edit_tweet_path(tweet) /tweets/1/edit Delete a tweet tweet, :method => :delete /tweets/1
  • 251. All links for Tweets <%= link_to "<link text>", <code> %> Action Code The URL Generated List all tweets tweets_path /tweets New tweet form new_tweet_path /tweets/new These paths n tweet = Tweet.find(1) eed a tweet Action Code The URL Generated Show a tweet tweet /tweets/1 Edit a tweet edit_tweet_path(tweet) /tweets/1/edit Delete a tweet tweet, :method => :delete /tweets/1
  • 252. All links for Tweets <%= link_to "<link text>", <code> %> Action Code The URL Generated List all tweets tweets_path /tweets New tweet form new_tweet_path /tweets/new These paths n tweet = Tweet.find(1) eed a tweet Action Code The URL Generated Show a tweet tweet /tweets/1 Edit a tweet edit_tweet_path(tweet) /tweets/1/edit Delete a tweet tweet, :method => :delete /tweets/1
  • 253. Zombie
  • 254. An Introduction to Rails Episode # This content is available free on created by http://RailsForZombies.org
  • 255. Chapter 4 r ai ns b v Controllers must be eaten
  • 257. Vie Our Application Stack ws Views Models 4 Components
  • 258. Vie Our Application Stack ws Views Controllers Models 4 Components
  • 259. Show a tweet /app/views/tweets/show.html.erb <!DOCTYPE html> <html> <head><title>Twitter for Zombies</title></head> <body> <img src="/images/twitter.png" /> FYI, This code <% tweet = Tweet.find(1) %> sucks a little.. <h1><%= tweet.status %></h1> (we’ll fix it later) <p>Posted by <%= tweet.zombie.name %></p> </body></html>
  • 260. /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 261. Request /tweets/1 /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 262. Request /tweets/1 Controller /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 263. zombie_twitter app Request controllers /tweets/1 tweets_controller.rb /app/controllers/tweets_controller.rb Controller /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 264. zombie_twitter app Request controllers tweets /tweets/1 tweets_controller.rb tweets /app/controllers/tweets_controller.rb Controller /app/views/tweets/show.html.erb tweets <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 265. Request /tweets/1 /app/controllers/tweets_controller.rb /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 266. Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController ... end /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 267. Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show end end /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 268. Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show end end /app/views/tweets/show.html.erb show <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 269. Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show end end /app/views/tweets/show.html.erb <% tweet = Tweet.find(1) %> <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 270. Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show tweet = Tweet.find(1) end end /app/views/tweets/show.html.erb <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 271. Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show tweet = Tweet.find(1) end end /app/views/tweets/show.html.erb <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 272. Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show tweet = Tweet.find(1) end end /app/views/tweets/show.html.erb <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 273. Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show tweet = Tweet.find(1) end end /app/views/tweets/show.html.erb What about <h1><%= tweet.status %></h1> variable scope? <p>Posted by <%= tweet.zombie.name %></p>
  • 274. Instance Variable Request /tweets/1 @ /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show tweet = Tweet.find(1) end end /app/views/tweets/show.html.erb <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 275. Instance Variable Request /tweets/1 @ /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show @ tweet = Tweet.find(1) end end /app/views/tweets/show.html.erb <h1><%= tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 276. Instance Variable Request /tweets/1 @ /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show @ tweet = Tweet.find(1) end end /app/views/tweets/show.html.erb <h1><%= @ tweet.status %></h1> <p>Posted by <%= tweet.zombie.name %></p>
  • 277. Instance Variable Request /tweets/1 @ /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show @ tweet = Tweet.find(1) end end /app/views/tweets/show.html.erb <h1><%= @ tweet.status %></h1> <p>Posted by <%= @ tweet.zombie.name %></p>
  • 278. Render Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show @ tweet = Tweet.find(1) end end /app/views/tweets/status.html.erb <h1><%= @ tweet.status %></h1> <p>Posted by <%= @ tweet.zombie.name %></p>
  • 279. Render Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show @ tweet = Tweet.find(1) end end /app/views/tweets/status.html.erb <h1><%= @ tweet.status %></h1> <p>Posted by <%= @ tweet.zombie.name %></p>
  • 280. Render Request /tweets/1 /app/controllers/tweets_controller.rb class TweetsController < ApplicationController def show @ tweet = Tweet.find(1) end end /app/views/tweets/status.html.erb <h1><%= @ tweet.status %></h1> <p>Posted by <%= @ tweet.zombie.name %></p>

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. \n
  158. \n
  159. \n
  160. \n
  161. \n
  162. \n
  163. \n
  164. \n
  165. \n
  166. \n
  167. \n
  168. \n
  169. \n
  170. \n
  171. \n
  172. \n
  173. \n
  174. \n
  175. \n
  176. \n
  177. \n
  178. \n
  179. \n
  180. \n
  181. \n
  182. \n
  183. \n
  184. \n
  185. \n
  186. \n
  187. \n
  188. \n
  189. \n
  190. \n
  191. \n
  192. \n
  193. \n
  194. \n
  195. \n
  196. \n
  197. \n
  198. \n
  199. \n
  200. \n
  201. \n
  202. \n
  203. \n
  204. \n
  205. \n
  206. \n
  207. \n
  208. \n
  209. \n
  210. \n
  211. \n
  212. \n
  213. \n
  214. \n
  215. \n
  216. \n
  217. \n
  218. \n
  219. \n
  220. \n
  221. \n
  222. \n
  223. \n
  224. \n
  225. \n
  226. \n
  227. \n
  228. \n
  229. \n
  230. \n
  231. \n
  232. \n
  233. \n
  234. \n
  235. \n
  236. \n
  237. \n
  238. \n
  239. \n
  240. \n
  241. \n
  242. \n
  243. \n
  244. \n
  245. \n
  246. \n
  247. \n
  248. \n
  249. \n
  250. \n
  251. \n
  252. \n
  253. \n
  254. \n
  255. \n
  256. \n
  257. \n
  258. \n
  259. \n
  260. \n
  261. \n
  262. \n
  263. \n
  264. \n
  265. \n
  266. \n
  267. \n
  268. \n
  269. \n
  270. \n
  271. \n
  272. \n
  273. \n
  274. \n
  275. \n
  276. \n
  277. \n
  278. \n
  279. \n
  280. \n
  281. \n
  282. \n
  283. \n
  284. \n
  285. \n
  286. \n
  287. \n
  288. \n
  289. \n
  290. \n
  291. \n
  292. \n
  293. \n
  294. \n
  295. \n
  296. \n
  297. \n
  298. \n
  299. \n
  300. \n
  301. \n
  302. \n
  303. \n
  304. \n
  305. \n
  306. \n
  307. \n
  308. \n
  309. \n
  310. \n
  311. \n
  312. \n
  313. \n
  314. \n
  315. \n
  316. \n
  317. \n
  318. \n
  319. \n
  320. \n
  321. \n
  322. \n
  323. \n
  324. \n
  325. \n
  326. \n
  327. \n
  328. \n
  329. \n
  330. \n
  331. \n
  332. \n
  333. \n
  334. \n
  335. \n
  336. \n
  337. \n
  338. \n
  339. \n
  340. \n
  341. \n
  342. \n
  343. \n
  344. \n
  345. \n
  346. \n
  347. \n
  348. \n
  349. \n
  350. \n
  351. \n
  352. \n
  353. \n
  354. \n
  355. \n
  356. \n
  357. \n
  358. \n
  359. \n
  360. \n
  361. \n
  362. \n
  363. \n
  364. \n
  365. \n
  366. \n
  367. \n
  368. \n
  369. \n
  370. \n
  371. \n
  372. \n
  373. \n
  374. \n
  375. \n
  376. \n
  377. \n
  378. \n
  379. \n
  380. \n
  381. \n
  382. \n
  383. \n
  384. \n
  385. \n
  386. \n
  387. \n
  388. \n
  389. \n
  390. \n
  391. \n
  392. \n
  393. \n
  394. \n
  395. \n
  396. \n
  397. \n
  398. \n
  399. \n
  400. \n
  401. \n
  402. \n
  403. \n
  404. \n
  405. \n
  406. \n
  407. \n
  408. \n
  409. \n
  410. \n
  411. \n
  412. \n
  413. \n
  414. \n
  415. \n
  416. \n
  417. \n
  418. \n
  419. \n
  420. \n
  421. \n
  422. \n
  423. \n
  424. \n
  425. \n
  426. \n
  427. \n
  428. \n
  429. \n
  430. \n
  431. \n
  432. \n
  433. \n
  434. \n
  435. \n
  436. \n
  437. \n
  438. \n
  439. \n
  440. \n
  441. \n
  442. \n
  443. \n
  444. \n
  445. \n
  446. \n
  447. \n
  448. \n
  449. \n
  450. \n
  451. \n
  452. \n
  453. \n
  454. \n
  455. \n
  456. \n
  457. \n
  458. \n
  459. \n
  460. \n
  461. \n
  462. \n
  463. \n
  464. \n
  465. \n
  466. \n
  467. \n
  468. \n
  469. \n
  470. \n
  471. \n
  472. \n
  473. \n
  474. \n
  475. \n
  476. \n
  477. \n
  478. \n
  479. \n
  480. \n
  481. \n
  482. \n
  483. \n
  484. \n
  485. \n
  486. \n
  487. \n
  488. \n
  489. \n
  490. \n
  491. \n
  492. \n
  493. \n
  494. \n
  495. \n
  496. \n
  497. \n
  498. \n
  499. \n
  500. \n
  501. \n
  502. \n
  503. \n
  504. \n
  505. \n
  506. \n
  507. \n
  508. \n
  509. \n
  510. \n
  511. \n
  512. \n
  513. \n
  514. \n
  515. \n
  516. \n
  517. \n
  518. \n
  519. \n
  520. \n
  521. \n
  522. \n
  523. \n
  524. \n
  525. \n
  526. \n
  527. \n
  528. \n
  529. \n
  530. \n
  531. \n
  532. \n
  533. \n
  534. \n
  535. \n
  536. \n
  537. \n
  538. \n
  539. \n
  540. \n
  541. \n
  542. \n
  543. \n
  544. \n
  545. \n
  546. \n
  547. \n
  548. \n
  549. \n
  550. \n
  551. \n
  552. \n
  553. \n
  554. \n
  555. \n
  556. \n
  557. \n
  558. \n
  559. \n
  560. \n
  561. \n
  562. \n
  563. \n
  564. \n
  565. \n
  566. \n
  567. \n
  568. \n
  569. \n
  570. \n
  571. \n
  572. \n
  573. \n
  574. \n
  575. \n
  576. \n
  577. \n
  578. \n
  579. \n
  580. \n
  581. \n
  582. \n
  583. \n
  584. \n
  585. \n
  586. \n
  587. \n
  588. \n
  589. \n
  590. \n
  591. \n
  592. \n
  593. \n
  594. \n
  595. \n
  596. \n
  597. \n
  598. \n
  599. \n
  600. \n
  601. \n
  602. \n
  603. \n
  604. \n
  605. \n
  606. \n
  607. \n
  608. \n
  609. \n
  610. \n
  611. \n
  612. \n
  613. \n
  614. \n
  615. \n
  616. \n
  617. \n
  618. \n
  619. \n
  620. \n
  621. \n
  622. \n
  623. \n
  624. \n
  625. \n
  626. \n
  627. \n
  628. \n
  629. \n
  630. \n
  631. \n
  632. \n
  633. \n
  634. \n
  635. \n
  636. \n
  637. \n
  638. \n
  639. \n
  640. \n
  641. \n
  642. \n
  643. \n
  644. \n
  645. \n
  646. \n
  647. \n
  648. \n
  649. \n
  650. \n
  651. \n
  652. \n
  653. \n
  654. \n
  655. \n
  656. \n
  657. \n
  658. \n
  659. \n
  660. \n
  661. \n
  662. \n
  663. \n
  664. \n
  665. \n
  666. \n
  667. \n
  668. \n
  669. \n
  670. \n
  671. \n
  672. \n
  673. \n
  674. \n
  675. \n
  676. \n
  677. \n
  678. \n
  679. \n
  680. \n
  681. \n
  682. \n
  683. \n
  684. \n
  685. \n
  686. \n
  687. \n
  688. \n
  689. \n
  690. \n
  691. \n
  692. \n
  693. \n
  694. \n
  695. \n
  696. \n
  697. \n
  698. \n
  699. \n
  700. \n
  701. \n
  702. \n
  703. \n
  704. \n
  705. \n
  706. \n
  707. \n
  708. \n
  709. \n
  710. \n
  711. \n
  712. \n
  713. \n
  714. \n
  715. \n
  716. \n
  717. \n
  718. \n
  719. \n
  720. \n
  721. \n
  722. \n
  723. \n
  724. \n
  725. \n
  726. \n
  727. \n
  728. \n
  729. \n
  730. \n
  731. \n
  732. \n
  733. \n
  734. \n
  735. \n
  736. \n
  737. \n
  738. \n
  739. \n
  740. \n
  741. \n
  742. \n
  743. \n
  744. \n
  745. \n
  746. \n
  747. \n
  748. \n
  749. \n
  750. \n
  751. \n
  752. \n
  753. \n
  754. \n
  755. \n
  756. \n
  757. \n
  758. \n
  759. \n
  760. \n
  761. \n
  762. \n
  763. \n
  764. \n
  765. \n
  766. \n
  767. \n
  768. \n
  769. \n
  770. \n
  771. \n
  772. \n
  773. \n
  774. \n
  775. \n
  776. \n
  777. \n
  778. \n
  779. \n
  780. \n
  781. \n
  782. \n
  783. \n
  784. \n
  785. \n
  786. \n
  787. \n
  788. \n
  789. \n
  790. \n
  791. \n
  792. \n
  793. \n
  794. \n
  795. \n
  796. \n
  797. \n
  798. \n
  799. \n
  800. \n
  801. \n
  802. \n
  803. \n
  804. \n
  805. \n
  806. \n
  807. \n
  808. \n
  809. \n
  810. \n
  811. \n
  812. \n
  813. \n
  814. \n
  815. \n
  816. \n
  817. \n
  818. \n
  819. \n
  820. \n
  821. \n
  822. \n
  823. \n
  824. \n
  825. \n
  826. \n
  827. \n
  828. \n
  829. \n
  830. \n
  831. \n
  832. \n