Chat with Thomas | Profile

Welcome to the Modern Web Design.

Lecture 1—Beginning Rails

Hi there,

In this lecture, we learn the most basic things about Ruby on Rails. Specifically, we learn:

  • What is Ruby, and Rails
  • Framework vs Library
  • Rails is a framework
  • Why Rails?
  • Rails development environment
  • Using Cloud9 development
  • Running the default screen
  • Convention over Configuration
  • Configure initializers
  • DRY principle

Here is the video screencast for the lecture 1:

 

Lab 1—Getting familiar with Ruby on Rails environment

After this lecture, you should be able to complete the following lab 1 exercise:

  • [Lab 1.1] Finish the TryRuby.org
  • [Lab 1.2] Getting the Rails up-and-running
  • [Lab 1.3] Post Scaffold

[Lab 1.1] Finish the TryRuby.org

In this lab, we have a glimpse on the Ruby language.

Time for Action:

  1. Browse to the TryRuby.org and complete all the tutorials there.

Checkpoint:

  1. You have completed the TryRuby.org.

[Lab 1.2] Getting the Rails up-and-running

In this lab, we setup the Rails development environment.

Time for Action:

  1. Setting up the Ruby on Rails on Cloud9 IDE, or any development environment on your choices.
  2. Boot-up the rails development server via `rails server`

Checkpoint:

  1. Rails application can run without error.
  2. You can see the default Rails welcome screen.

[Lab 1.3] Post Scaffold

In this lab, we create a Post CRUD by using the Rails scaffold generation.

Time for Action:

  1. In the terminal, make user we are in the Rails project directory.
  2. Type `rails generate scaffold Post title author content:text is_published:boolean`
  3. In the generated migration file, set the default value of `is_published` to `true`.

Checkpoint:

  1. Can list all posts in `/posts/`
  2. Can create post via `/posts/new`
  3. Can show one post via `/posts/:id`
  4. Can edit post via `/posts/:id/edit`
  5. Can delete post via `/posts/:id` (DELETE)
  6. Content showing preserves the line break.

After you finish all the lab exercises, please explore the ActiveRecord by running different commands in rails console. For example, you may run:

  • `Date.current + 3.days`
  • `Post.all`
  • `Post.all.reverse`
  • `Post.all.count`
  • `p = Post.new`
  • `Post.where('created_at > ?', Date.current)`