March 2025
Intermediate to advanced
472 pages
12h 10m
English
Let’s look at an example of how Rails applies a number of Ruby features together to make the code you need to maintain more declarative. You’ll see this example again in Generating the Scaffold. For now, we’ll focus on the Ruby-language aspects of the example:
| | class CreateProducts < ActiveRecord::Migration[7.2] |
| | def change |
| | create_table :products do |t| |
| | t.string :title |
| | t.text :description |
| | t.string :image_url |
| » | t.decimal :price, precision: 8, scale: 2 |
| | |
| | t.timestamps |
| | end |
| | end |
| | end |
Even if you didn’t know any Ruby, you’d probably be able to decipher that this code creates a table named products. The fields defined when this table is created include title, description ...
Read now
Unlock full access