Question 3 - Creer une creature

pull/1/head
Karim Bogtob 2 years ago
parent 2fdbde6e4b
commit 09c559caf6

@ -9,3 +9,10 @@ Question 2.2 :
Question 2.3 :
* `rails generate controller HomeController`
Question 3 :
* `rails generate model Creature name:string health_points:integer`
* La migration n'est pas lancée sur la base
* `rails db:migrate`

@ -0,0 +1,5 @@
class Creature < ApplicationRecord
def to_label
"#{name} (#{health_points})"
end
end

@ -0,0 +1,10 @@
class CreateCreatures < ActiveRecord::Migration[7.0]
def change
create_table :creatures do |t|
t.string :name
t.integer :health_points
t.timestamps
end
end
end

21
db/schema.rb generated

@ -0,0 +1,21 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_03_26_131540) do
create_table "creatures", force: :cascade do |t|
t.string "name"
t.integer "health_points"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end

@ -0,0 +1,9 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
health_points: 1
two:
name: MyString
health_points: 1

@ -0,0 +1,7 @@
require "test_helper"
class CreatureTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Loading…
Cancel
Save