Corrigé du TP3 / 4 / Début du 5 - Regarder commit par commit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
Karim Bogtob f5bdb92a2a
2.5 - Scope alive
2 years ago
app 2.5 - Scope alive 2 years ago
bin Initial commit 2 years ago
config 2.5 - Supprimer une creature 2 years ago
db Question 3.2 - Peupler la base 2 years ago
lib Initial commit 2 years ago
log Initial commit 2 years ago
public Initial commit 2 years ago
storage Initial commit 2 years ago
test Question 3 - Creer une creature 2 years ago
tmp Initial commit 2 years ago
vendor Initial commit 2 years ago
.gitattributes Initial commit 2 years ago
.gitignore Initial commit 2 years ago
.ruby-version Initial commit 2 years ago
Gemfile Question 3.2 - Peupler la base 2 years ago
Gemfile.lock Question 3.2 - Peupler la base 2 years ago
README.md 2.5 - Scope alive 2 years ago
Rakefile Initial commit 2 years ago
config.ru Initial commit 2 years ago

README.md

README

Commandes lancées :

Question 2.2 :

  • rails server

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

Question 3.1 :

Je teste la creature dans une console rails que je lance avec rails console :

 rails console
Loading development environment (Rails 7.0.4.3)
irb(main):001:0> c = Creature.create(name: "Thrall", health_points: 489)
  TRANSACTION (0.1ms)  begin transaction
  Creature Create (0.4ms)  INSERT INTO "creatures" ("name", "health_points", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["name", "Thrall"], ["health_points", 489], ["created_at", "2023-03-26 13:19:57.492017"], ["updated_at", "2023-03-26 13:19:57.492017"]]
  TRANSACTION (0.9ms)  commit transaction
=>
#<Creature:0x00000001070374f8
...
irb(main):002:0> c.to_label
=> "Thrall (489)"

Question 3.2 :

  • bundle add random_name_generator pour ajouter la gemme au gemfile, effectuer la résolution de dépendance et installer la nouvelle gemme

  • rails db:seed

TP4

Question 2.5 :

  • J'ajoute une créature avec des PVs à 0 :
 rails console
Loading development environment (Rails 7.0.4.3)
irb(main):001:0> Creature.create(name: 'Zombie', health_points: 0)
  TRANSACTION (0.1ms)  begin transaction
  Creature Create (0.4ms)  INSERT INTO "creatures" ("name", "health_points", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["name", "Zombie"], ["health_points", 0], ["created_at", "2023-03-26 14:00:56.413028"], ["updated_at", "2023-03-26 14:00:56.413028"]]
  TRANSACTION (0.9ms)  commit transaction
=>
#<Creature:0x00000001104b9310
 id: 27,
 name: "Zombie",
 health_points: 0,
 created_at: Sun, 26 Mar 2023 14:00:56.413028000 UTC +00:00,
 updated_at: Sun, 26 Mar 2023 14:00:56.413028000 UTC +00:00>
  • J'essaie de renommer la créature dans postman et je vérifie que son nom ne change pas

  • J'ai bien une 404 et son nom n'a pas changé