June 2025
Intermediate to advanced
488 pages
12h 27m
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[8.0] |
| | def change |
| | create_table :products do |t| |
| | t.string :title |
| | t.text :description |
| » | 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, and price, as well as a ...
Read now
Unlock full access