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:
- Browse to the TryRuby.org and complete all the tutorials there.
Checkpoint:
- 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:
- Setting up the Ruby on Rails on Cloud9 IDE, or any development environment on your choices.
- Boot-up the rails development server via `rails server`
Checkpoint:
- Rails application can run without error.
- 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:
- In the terminal, make user we are in the Rails project directory.
- Type `rails generate scaffold Post title author content:text is_published:boolean`
- In the generated migration file, set the default value of `is_published` to `true`.
Checkpoint:
- Can list all posts in `/posts/`
- Can create post via `/posts/new`
- Can show one post via `/posts/:id`
- Can edit post via `/posts/:id/edit`
- Can delete post via `/posts/:id` (DELETE)
- 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)`