Make-a the models
This commit is contained in:
parent
14665a2837
commit
675181e954
13
app/controllers/games_controller.rb
Normal file
13
app/controllers/games_controller.rb
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class GamesController < ApplicationController
|
||||||
|
def index
|
||||||
|
@games = Game.all
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@game = Game.find(params["id"])
|
||||||
|
clocks = @game.clocks
|
||||||
|
resources = @game.resources
|
||||||
|
morales = @game.morales
|
||||||
|
@trackers = clocks + resources + morales
|
||||||
|
end
|
||||||
|
end
|
||||||
8
app/controllers/trackers_controller.rb
Normal file
8
app/controllers/trackers_controller.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class TrackersController < ApplicationController
|
||||||
|
def index
|
||||||
|
@clocks = Clock.all
|
||||||
|
@resources = Resource.all
|
||||||
|
@morales = Morale.all
|
||||||
|
@trackers = @clocks + @resources + @morales
|
||||||
|
end
|
||||||
|
end
|
||||||
5
app/models/clock.rb
Normal file
5
app/models/clock.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class Clock < ApplicationRecord
|
||||||
|
def type
|
||||||
|
"clock"
|
||||||
|
end
|
||||||
|
end
|
||||||
6
app/models/game.rb
Normal file
6
app/models/game.rb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class Game < ApplicationRecord
|
||||||
|
has_many :clocks
|
||||||
|
has_many :resources
|
||||||
|
has_many :morales
|
||||||
|
has_many :text_trackers
|
||||||
|
end
|
||||||
5
app/models/morale.rb
Normal file
5
app/models/morale.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class Morale < ApplicationRecord
|
||||||
|
def type
|
||||||
|
"morale"
|
||||||
|
end
|
||||||
|
end
|
||||||
5
app/models/resource.rb
Normal file
5
app/models/resource.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class Resource < ApplicationRecord
|
||||||
|
def type
|
||||||
|
"resources"
|
||||||
|
end
|
||||||
|
end
|
||||||
2
app/models/text_tracker.rb
Normal file
2
app/models/text_tracker.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class TextTracker < ApplicationRecord
|
||||||
|
end
|
||||||
2
app/models/text_tracker_message.rb
Normal file
2
app/models/text_tracker_message.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class TextTrackerMessage < ApplicationRecord
|
||||||
|
end
|
||||||
4
app/views/games/index.html.erb
Normal file
4
app/views/games/index.html.erb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<h1>Games</h1>
|
||||||
|
<% @games.each do |game| %>
|
||||||
|
<h2><a href="<%= game_path(game.id) %>"><%= game.name %></a></h2>
|
||||||
|
<% end %>
|
||||||
4
app/views/games/show.html.erb
Normal file
4
app/views/games/show.html.erb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<h1><%= @game.name %></h1>
|
||||||
|
<% @trackers.each do |tracker| %>
|
||||||
|
<h2><%= tracker.name %>(<%= tracker.type %>)</h2>
|
||||||
|
<% end %>
|
||||||
4
app/views/trackers/index.html.erb
Normal file
4
app/views/trackers/index.html.erb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<h1>Trackers</h1>
|
||||||
|
<% @trackers.each do |tracker| %>
|
||||||
|
<h2><%= tracker.name %>(<%= tracker.type %>)</h2>
|
||||||
|
<% end %>
|
||||||
@ -11,4 +11,7 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
# Defines the root path route ("/")
|
# Defines the root path route ("/")
|
||||||
# root "posts#index"
|
# root "posts#index"
|
||||||
|
resources :games do
|
||||||
|
resources :trackers
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
11
db/migrate/20260202002624_create_clocks.rb
Normal file
11
db/migrate/20260202002624_create_clocks.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class CreateClocks < ActiveRecord::Migration[8.1]
|
||||||
|
def change
|
||||||
|
create_table :clocks do |t|
|
||||||
|
t.integer :game_id
|
||||||
|
t.string :name
|
||||||
|
t.integer :value
|
||||||
|
t.integer :max_value
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
11
db/migrate/20260202002634_create_resources.rb
Normal file
11
db/migrate/20260202002634_create_resources.rb
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class CreateResources < ActiveRecord::Migration[8.1]
|
||||||
|
def change
|
||||||
|
create_table :resources do |t|
|
||||||
|
t.integer :game_id
|
||||||
|
t.string :name
|
||||||
|
t.integer :value
|
||||||
|
t.integer :max_value
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
12
db/migrate/20260202002643_create_morales.rb
Normal file
12
db/migrate/20260202002643_create_morales.rb
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
class CreateMorales < ActiveRecord::Migration[8.1]
|
||||||
|
def change
|
||||||
|
create_table :morales do |t|
|
||||||
|
t.integer :game_id
|
||||||
|
t.string :name
|
||||||
|
t.float :value
|
||||||
|
t.float :min_value
|
||||||
|
t.float :max_value
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
9
db/migrate/20260202002709_create_text_trackers.rb
Normal file
9
db/migrate/20260202002709_create_text_trackers.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class CreateTextTrackers < ActiveRecord::Migration[8.1]
|
||||||
|
def change
|
||||||
|
create_table :text_trackers do |t|
|
||||||
|
t.integer :game_id
|
||||||
|
t.string :name
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
class CreateTextTrackerMessages < ActiveRecord::Migration[8.1]
|
||||||
|
def change
|
||||||
|
create_table :text_tracker_messages do |t|
|
||||||
|
t.integer :text_tracker_id
|
||||||
|
t.text :text
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
8
db/migrate/20260202002823_create_games.rb
Normal file
8
db/migrate/20260202002823_create_games.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class CreateGames < ActiveRecord::Migration[8.1]
|
||||||
|
def change
|
||||||
|
create_table :games do |t|
|
||||||
|
t.string :name
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
49
db/schema.rb
generated
49
db/schema.rb
generated
@ -10,5 +10,52 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.1].define(version: 0) do
|
ActiveRecord::Schema[8.1].define(version: 2026_02_02_002823) do
|
||||||
|
create_table "clocks", force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.integer "game_id"
|
||||||
|
t.integer "max_value"
|
||||||
|
t.string "name"
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "value"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "games", force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.string "name"
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "morales", force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.integer "game_id"
|
||||||
|
t.float "max_value"
|
||||||
|
t.float "min_value"
|
||||||
|
t.string "name"
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.float "value"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "resources", force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.integer "game_id"
|
||||||
|
t.integer "max_value"
|
||||||
|
t.string "name"
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "value"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "text_tracker_messages", force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.text "text"
|
||||||
|
t.integer "text_tracker_id"
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "text_trackers", force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.integer "game_id"
|
||||||
|
t.string "name"
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
7
test/models/clock_test.rb
Normal file
7
test/models/clock_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ClockTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
test/models/game_test.rb
Normal file
7
test/models/game_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class GameTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
test/models/morale_test.rb
Normal file
7
test/models/morale_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class MoraleTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
test/models/resource_test.rb
Normal file
7
test/models/resource_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ResourceTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
test/models/text_tracker_message_test.rb
Normal file
7
test/models/text_tracker_message_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class TextTrackerMessageTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
test/models/text_tracker_test.rb
Normal file
7
test/models/text_tracker_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class TextTrackerTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user