Skip to content

Commit 079297d

Browse files
committed
+ scripts/createdb.js + database part
1 parent 37db3ff commit 079297d

File tree

17 files changed

+199
-1
lines changed

17 files changed

+199
-1
lines changed

src/components/ShellConfigurator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const ShellConfigurator: React.FC = () => {
2525

2626
const conf = tutorialStore.lesson?.data?.custom?.shell as ShellConfig
2727
if (conf) {
28-
const workdir = conf.workdir;
28+
const { workdir } = conf;
2929

3030
if (workdir) {
3131
terminal.input(`cd /home/tutorial${workdir} && clear\n`);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
type: lesson
3+
title: Autoloading in Development
4+
editor: false
5+
terminal: false
6+
---
7+
8+
Autoloading in Development
9+
----------------
10+
11+
Developer happiness is a cornerstone philosophy of Rails and one way of
12+
achieving this is with automatic code reloading in development.
13+
14+
Once you start the Rails server, new files or changes to existing files are
15+
detected and automatically loaded or reloaded as necessary. This allows you to
16+
focus on building without having to restart your Rails server after every
17+
change.
18+
19+
You may also notice that Rails applications rarely use `require` statements like
20+
you may have seen in other programming languages. Rails uses naming conventions
21+
to require files automatically so you can focus on writing your application
22+
code.
23+
24+
See
25+
[Autoloading and Reloading Constants](https://guides.rubyonrails.org/autoloading_and_reloading_constants.html)
26+
for more details.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../../../../templates/rails-new"
3+
}

src/content/tutorial/4-database/1-generate-model/_files/workspace/.keep

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
type: lesson
3+
title: Model generator
4+
custom:
5+
shell:
6+
workdir: "/workspace/store"
7+
---
8+
9+
Generate a model
10+
----------------
11+
12+
Active Record is a feature of Rails that maps relational databases to Ruby code.
13+
It helps generate the structured query language (SQL) for interacting with the
14+
database like creating, updating, and deleting tables and records. Our
15+
application is using SQLite which is the default for Rails.
16+
17+
Let's start by adding a database table to our Rails application to add products
18+
to our simple e-commerce store. Run the following command in the terminal:
19+
20+
```bash
21+
$ bin/rails generate model Product name:string
22+
```
23+
24+
This command tells Rails to generate a model named `Product` which has a `name`
25+
column and type of `string` in the database. Later on, you'll learn how to add
26+
other column types.
27+
28+
You should see the following in your terminal:
29+
30+
```bash
31+
invoke active_record
32+
create db/migrate/20250526151900_create_products.rb
33+
create app/models/product.rb
34+
invoke test_unit
35+
create test/models/product_test.rb
36+
create test/fixtures/products.yml
37+
```
38+
39+
This command does several things. It creates...
40+
41+
1. A migration in the `db/migrate` folder.
42+
2. An Active Record model in `app/models/product.rb`.
43+
3. Tests and test fixtures for this model.
44+
45+
:::info
46+
Model names are *singular*, because an instantiated model represents a
47+
single record in the database (i.e., You are creating a _product_ to add to the
48+
database.).
49+
:::
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../../../../templates/rails-new"
3+
}

src/content/tutorial/4-database/2-database-migrations/_files/workspace/.keep

Whitespace-only changes.

src/content/tutorial/4-database/2-database-migrations/_files/workspace/store/app/models/product.rb

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class CreateProducts < ActiveRecord::Migration[8.0]
2+
def change
3+
create_table :products do |t|
4+
t.string :name
5+
6+
t.timestamps
7+
end
8+
end
9+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2+
3+
one:
4+
name: MyString
5+
6+
two:
7+
name: MyString

0 commit comments

Comments
 (0)