Learn Enough to Be Dangerous
You have to make a choice. Choose...wisely.

Get occasional notifications about things like product discounts, blog posts, and new or updated tutorials. Unsubscribe at any time.

Quick Checkout
or Pay by Credit Card
Error processing your payment
  • You didn't choose whether or not to be added to the mailing list
Confirm
$0.00

Payments and credit card details are securely managed and protected by Learn Enough's payment processor, Stripe. More information on their site:

CART
Total
$0.00

Your Cart is Empty

$30
$300
$300
$XY
$XY
1234
  • Ruby on Rails (Rails 6)

Learn Enough Society

Certificate of Course Completion

This page certifies that mokubo has completed Ruby on Rails Tutorial! 🎉

About the tutorial
Since its initial publication in 2010, the Ruby on Rails Tutorial has been one of the leading introductions to web development. In this bestselling tutorial, you’ll learn how to develop and deploy real, industrial-strength web applications with Ruby on Rails, the open-source web framework that powers top websites such as Hulu, GitHub, Shopify, and Airbnb. This new 6th edition has been fully updated for Rails 6. Read full post
17 Mar 15:45, 2020
18 Nov 02:13, 2020
Exercise Answers
Exercise Question:
  • Confirm that GitHub renders the Markdown for the README in Listing 3.3 as HTML (Figure 3.2).
  • mokubo's Answer:

    Confirmed

    Exercise Question:
  • By visiting the root route on the production server, verify that the deployment to Heroku succeeded.
  • mokubo's Answer:

    200

    Exercise Question:
  • Assign variables city and state to your current city and state of residence. (If residing outside the U.S., substitute the analogous quantities.)
  • mokubo's Answer:
    $ irb
    >> city = "San Francisco"
    => "San Francisco"
    >> states = "California"
    => "California"
    >> puts "#{city}, #{states}"
    San Francisco, California
    => nil
    >>
    
    Exercise Question:
  • Using interpolation, print (using puts) a string consisting of the city and state separated by a comma and a space, as in “Los Angeles, CA”.
  • mokubo's Answer:
    $ irb
    >> city = "San Francisco"
    => "San Francisco"
    >> states = "California"
    => "California"
    >> puts "#{city}, #{states}"
    San Francisco, California
    => nil
    >>
    
    
    
    Exercise Question:
  • Repeat the previous exercise but with the city and state separated by a tab character.
  • mokubo's Answer:
    >> puts "#{city}\t#{states}"
    San Francisco	California
    => nil
    >>
    
    Exercise Question:
  • What is the result if you replace double quotes with single quotes in the previous exercise?
  • mokubo's Answer:

    Printed nothing

    >> puts ""#{city}\t#{states}""
    
    => nil
    >>
    
    Exercise Question:
  • What is the length of the string “racecar”?
  • mokubo's Answer:
    >> "racecar".length
    => 7
    >>
    
    Exercise Question:
  • Confirm using the reverse method that the string in the previous exercise is the same when its letters are reversed.
  • mokubo's Answer:
    >> "racecar".reverse
    => "racecar"
    >>
    
    Exercise Question:
  • Assign the string “racecar” to the variable s. Confirm using the comparison operator == that s and s.reverse are equal.
  • mokubo's Answer:
    >> s = "racecar"
    => "racecar"
    >> s == s.reverse
    => true
    >>
    
    Exercise Question:
  • What is the result of running the code shown in Listing 4.9? How does it change if you reassign the variable s to the string “onomatopoeia”? Hint: Use up-arrow to retrieve and edit previous commands
  • mokubo's Answer:
    >> s = "onomatopoeia"
    => "onomatopoeia"
    >> s == s.reverse
    => false
    >>
    
    Exercise Question:
  • In the console, confirm that you can use interpolation (Section 4.2.1) to interpolate a raw symbol. For example, what is the return value of "#{:success}"?
  • mokubo's Answer:
    >> flash.each do |key, value|
    ?> puts "#{:success}"
    >> end
    success
    success
    => {:success=>"It worked!", :danger=>"It faild!"}
    >>
    

    OR

    >> puts "#{:success}"
    success
    => nil
    >>
    
    Exercise Question:
  • How does the previous exercise relate to the flash iteration shown in Listing 7.28?
  • mokubo's Answer:

    It shows prints value in message types and changes it.

    Exercise Question:
  • According to the default Rails page, what is the version of Ruby on your system? Confirm by running ruby -v at the command line.
  • mokubo's Answer:
    $ ruby -v
    ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin19]
    $
    
    Exercise Question:
  • What is the version of Rails? Confirm that it matches the version installed in Listing 1.2.
  • mokubo's Answer:
    $ rails -v
    Rails 6.0.3.4
    
    Exercise Question:
  • Change the content of the hello action in Listing 1.13 to read “hola, mundo!” instead of “hello, world!”.
  • mokubo's Answer:
    class ApplicationController < ActionController::Base
    
      def hello
        render html: "hola, mundo!"
      end
    end
    
    
    Exercise Question:
  • Show that Rails supports non-ASCII characters by including an inverted exclamation point, as in “¡Hola, mundo!” (Figure 1.21).15 To get a ¡ character on a Mac, you can use Option-1; otherwise, you can always copy-and-paste the character into your editor.
  • mokubo's Answer:
    class ApplicationController < ActionController::Base
    
      def hello
        render html: "¡hola, mundo!"
      end
    end
    
    Exercise Question:
  • By following the example of the hello action in Listing 1.13, add a second action called goodbye that renders the text “goodbye, world!”. Edit the routes file from Listing 1.15 so that the root route goes to goodbye instead of to hello (Figure 1.22).
  • mokubo's Answer:
    class ApplicationController < ActionController::Base
    
      def hello
        render html: "hola, mundo!"
      end
    
      def goodbye
        render html: "goodbye, world!"
      end
    
    end
    
    Exercise Question:
  • Run heroku help to see a list of Heroku commands. (If the output of heroku help doesn’t fit in your terminal window, either scroll up or use heroku help | less to pipe to the less command.) What is the command to display logs for an app?
  • mokubo's Answer:

    heroku logs

    CLI to interact with Heroku
    
    VERSION
      heroku/7.47.1 darwin-x64 node-v12.16.2
    
    USAGE
      $ heroku [COMMAND]
    
    COMMANDS
      access          manage user access to apps
      addons          tools and services for developing, extending, and operating
                      your app
      apps            manage apps on Heroku
      auth            check 2fa status
      authorizations  OAuth authorizations
      autocomplete    display autocomplete installation instructions
      buildpacks      scripts used to compile apps
      certs           a topic for the ssl plugin
      ci              run an application test suite on Heroku
      clients         OAuth clients on the platform
      config          environment variables of apps
      container       Use containers to build and deploy Heroku apps
      domains         custom domains for apps
      drains          forward logs to syslog or HTTPS
      features        add/remove app features
      git             manage local git repository for app
      help            display help for heroku
      keys            add/remove account ssh keys
      labs            add/remove experimental features
      local           run Heroku app locally
      logs            display recent log output
      maintenance     enable/disable access to app
      members         manage organization members
      notifications   display notifications
      orgs            manage organizations
      pg              manage postgresql databases
      pipelines       manage pipelines
      plugins         list installed plugins
      ps              Client tools for Heroku Exec
      psql            open a psql shell to the database
      redis           manage heroku redis instances
      regions         list available regions for deployment
      releases        display the releases for an app
      reviewapps      manage reviewapps in pipelines
      run             run a one-off process inside a Heroku dyno
      sessions        OAuth sessions
      spaces          manage heroku private spaces
      status          status of the Heroku platform
      teams           manage teams
      update          update the Heroku CLI
      webhooks        list webhooks on an app
    
    
    Exercise Question:
  • It’s well-known that no web page is complete without a cat image. Using the command in Listing 5.4, arrange to download the kitten pic shown in Figure 5.3.11
  • mokubo's Answer:
    $ curl -OL https://cdn.learnenough.com/kitten.jpg
    
    
    Exercise Question:
  • In the console, set user to the first user in the database, and verify by calling it directly that the remember method works. How do remember_token and remember_digest compare?
  • mokubo's Answer:

    hi

    Join the Mailing List

    Get occasional notifications about things like product discounts, blog posts, and new or updated tutorials. Unsubscribe at any time.